0
0

laravelのassetヘルパ関数

Last updated at Posted at 2024-04-03

laraveのassetヘルパ関数について

参考URL:https://readouble.com/laravel/9.x/ja/helpers.html#method-asset

概要

  • asset()関数はlaravelのヘルパ関数
  • asset()は、publicフォルダのディレクトリパスを返す

使い方

asset('storage/' . $post->image)

これでpublicディレクトリ内のstorageという
ディレクトリの中のファイルにアクセスする。
つまりassetの中にpublicの中のファイルパスを書けばOK

$path = $request->file('image')->store('photos','public')

例えばフォームから画像を取得した際にstoreメソッドを使って、storage/app/public/
というローカルないのディレクトリに保存をする。
このstorageディレクトリは外部からのアクセスができないため、
リンクを貼ることで公開できる。

php artisan storage:link

public/storage にリンクが貼られpublicディレクトリは外部アクセスできるので、公開ができる。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0