[英]Laravel Storage::disk()->url(); does not work properly
你好,我在laravel遇到麻烦。
我想为某些东西(xls,图像,pdf等)创建私有存储。 一切在storage / app / public目录中都很好用,但是我不想要它,我想要像storage / app / products / {id} /
首先看一下我的代码:
filesystem.php
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
'productions' => [
'driver' => 'local',
'root' => storage_path('app/productions'),
'visibility' => 'private',
],
我创建新的数组“作品”
ProductionController.php
public function file()
{
return '<img src="'.Storage::disk('productions')->url('7/2.png').'">';
}
web.php(路由)
Route::group([
'middleware'=>'roles',
'roles'=>['Administrator','Prefabrykacja','Dyrektor Prefabrykacji']
], function () {
Route::get('/Produkcja',[
'uses'=>'ProductionController@index',
'as'=>'production.index']);
Route::post('/Produkcja/create',[
'uses'=>'ProductionController@create',
'as'=>'production.create']);
Route::get('/Produkcja/file',[
'uses'=>'ProductionController@file',
'as'=>'production.file']);
});
如果我回来
return '<img src="'.Storage::disk('productions')->url('7/2.png').'">';
要么
return '<img src="'.Storage::disk('local')->url('7/2.png').'">';
结果是一样的。 这两行都从storage / app / public / 7 / 2.png返回图像将不显示图像storage / app / products / 7 / 2.png
如何显示产品文件夹中的图像并将资源限制为指定角色?
问候
首先,您可能缺少public
链接这样的符号链接( Local URL Host Customization )。 另外,您需要指定url
参数(例如public
并更改对public
visibility
,以允许其他人查看您的文件。
filesystem.php:
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
'productions' => [
'driver' => 'local',
'root' => storage_path('app/productions'),
'url' => env('APP_URL') . '/productions', // added line (directory within "public")
'visibility' => 'public', // modified visibility
],
],
还要确保您在public/productions
创建一个符号链接,该链接将指向storage/app/productions
目录。 您可以使用以下命令来执行此操作(例如):
cd LARAVEL_PATH && ln -s storage/app/productions public/productions
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.