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ディレクトリは外部アクセスできるので、公開ができる。