我正在尝试将音频文件上传到数据库,但没有任何反应,我也没有收到任何错误。
控制器:
public function store (Request $request)
{
$this->validate(request(), [
'title' => 'required'
]);
$muzika = new Muzika;
if ($request->hasFile('featured_muzika')) {
$daina = $request->file('featured_muzika');
$filename = time(). '.' .$daina->getClientOriginalExtension();
$location = public_path('muzika/' . $filename);
Storage::disk('local')->save($location);
$muzika->daina = $filename;
}
$muzika->daina = $filename;
$muzika->title = $request->title;
$muzika->save();
return redirect('/');
}
这是我的表单,起初我只尝试过标题,它存储在DB中,当我为文件添加存储方法时它停止工作
{!! Form::open(array('route' => 'muzika.store', 'files' => true)) !!}
{{csrf_field()}}
{!! Form::label('title', 'Title:', ['class' => 'control-label']) !!}
{!! Form::text('title', null, ['class' => 'form-control']) !!}
{{ Form::label('featured_muzika', 'Upload Featured mp3:')}}
{{ Form::file('featured_muzika')}}
{!! Form::submit('Post', ['class' => 'btn btn-primary']) !!}
{!! Form:: close () !!}
当我按提交时它只重定向。数据库保持空白
答案 0 :(得分:1)
在laravel 5.5中你可以做到
$muzika = new Muzika();
$path = request()->file('featured_muzika')->store('/muzika');
$muzika->daina = $path;
$muzika->save();
确保您的表单设有enctype="multipart/form-data"
设置