你好,我的拉拉有麻烦。
我想创建一些东西的私人存储(xls,图像,pdf等)。所有的东西都在存储/app/公共目录中工作得很好,但是我不想要它,我想要我的目录,就像存储/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').'">';结果是一样的。这两行都返回存储/app/public/7/2. not将不显示图像存储/app/products/7/2.png
如何从“产品”文件夹中显示图像并将资源限制为指定角色?
问候
发布于 2017-07-16 20:47:17
首先,您可能缺少了public (本地URL主机定制)这样的符号链接。此外,您还需要指定url参数,比如public,并将visibility更改为public,以便让其他人查看您的文件。
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/productionshttps://stackoverflow.com/questions/45132441
复制相似问题