我正在尝试使我的Laravel Voyager应用程序通过Controller
而不是根据filesystems.php
的设置将帖子的新闻图像上传到另一个文件夹中
之所以这样做,是因为我希望张贴的文件结构井井有条,因此图像将放入名为“ 2019”的文件夹中。
反正有实现这一目标的方法吗?
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',
],
's3' => [
'driver' => 's3',
'key' => env('AWS_KEY'),
'secret' => env('AWS_SECRET'),
'region' => env('AWS_REGION'),
'bucket' => env('AWS_BUCKET'),
],
],
NewsController.php
public function store(Request $request)
{
$slug = $this->getSlug($request);
$dataType = Voyager::model('DataType')->where('slug', '=', $slug)->first();
// Check permission
$this->authorize('add', app($dataType->model_name));
// Validate fields with ajax
$val = $this->validateBread($request->all(), $dataType->addRows);
if ($val->fails()) {
return response()->json(['errors' => $val->messages()]);
}
if (!$request->has('_validate')) {
$data = $this->insertUpdateData($request, $slug, $dataType->addRows, new $dataType->model_name());
event(new BreadDataAdded($dataType, $data));
if ($request->ajax()) {
return response()->json(['success' => true, 'data' => $data]);
}
return redirect()
->route("voyager.{$dataType->slug}.index")
->with([
'message' => __('voyager::generic.successfully_added_new')." {$dataType->display_name_singular}",
'alert-type' => 'success',
]);
}
}