Kac*_*zor 7 php laravel laravel-5.4
你好,我在 laravel 中遇到了麻烦。
我想为一些东西(xls、图像、pdf 等)创建私人存储。在 storage/app/public 目录中一切都很好,但我不想要它,我想要我的目录,如 storage/app/products/{id}/
首先看我的代码:
文件系统.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',
],
Run Code Online (Sandbox Code Playgroud)
我创建新的数组“作品”
ProductionController.php
public function file()
{
return '<img src="'.Storage::disk('productions')->url('7/2.png').'">';
}
Run Code Online (Sandbox Code Playgroud)
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']);
});
Run Code Online (Sandbox Code Playgroud)
如果我回来
return '<img src="'.Storage::disk('productions')->url('7/2.png').'">';
Run Code Online (Sandbox Code Playgroud)
或者
return '<img src="'.Storage::disk('local')->url('7/2.png').'">';
Run Code Online (Sandbox Code Playgroud)
结果是一样的。这两行从 storage/app/public/7/2.png 返回图像将不显示图像 storage/app/products/7/2.png
如何显示产品文件夹中的图像并将资源限制为指定角色?
问候
小智 3
首先,您可能缺少像这样的符号链接public(本地 URL 主机自定义)。另外,您需要指定urlforpublic和更改visibilityto等参数public,以便其他人可以看到您的文件。
文件系统.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
],
],
Run Code Online (Sandbox Code Playgroud)
还要确保您创建一个public/productions指向storage/app/productions目录的符号链接。您可以使用以下命令来执行此操作(例如):
cd LARAVEL_PATH && ln -s storage/app/productions public/productions
Run Code Online (Sandbox Code Playgroud)