我想在注册到名为“fotodosen”的列时上传个人资料图片。我已经尝试了这个但仍然无效。
这是我在DosenController中的方法:
public function store(CreateDosenRequest $request)
{
$user = User::create([
'name' => $request->input('name'),
'username' => $request->input('username'),
'email' => $request->input('email'),
'password' => $request->input('password'),
'admin' => $request->input('admin'),
]);
$dosen = Dosen::create([
'iddosen' => $request->input('iddosen'),
'nipy' => $request->input('nipy'),
'namadosen' => $user->name,
'user_id' => $user->id,
'alamatdosen' => $request->input('alamatdosen'),
'notelpdosen' => $request->input('notelpdosen'),
'tempatlahirdosen' => $request->input('tempatlahirdosen'),
'tanggallahirdosen' => $request->input('tanggallahirdosen'),
'agamadosen' => $request->input('agamadosen'),
]);
return redirect('admin/dosen')->with('message', 'Data berhasil ditambahkan!');
}
我已经尝试过了:
public function store(CreateDosenRequest $request)
{
$user = User::create([
'name' => $request->input('name'),
'username' => $request->input('username'),
'email' => $request->input('email'),
'password' => $request->input('password'),
'admin' => $request->input('admin'),
]);
$dosen = Dosen::create([
'iddosen' => $request->input('iddosen'),
'nipy' => $request->input('nipy'),
'namadosen' => $user->name,
'user_id' => $user->id,
'alamatdosen' => $request->input('alamatdosen'),
'notelpdosen' => $request->input('notelpdosen'),
'tempatlahirdosen' => $request->input('tempatlahirdosen'),
'tanggallahirdosen' => $request->input('tanggallahirdosen'),
'agamadosen' => $request->input('agamadosen'),
]);
if($request->hasFile('fotodosen')){
$file = Input::file('fotodosen');
$file = $file->move(public_path().'/uploads/',$file->getOriginalFileName());
$user->fotodosen = $file->getRealPath();
}
$user->save();
return $user;
return redirect('admin/dosen')->with('message', 'Data berhasil ditambahkan!');
}
但它仍然无效。
这是我的表格:
{{ Form::open(array('url' => 'admin/dosen', 'files' => true, 'method' => 'post')) }}
{!! Form::file('fotodosen', null) !!}
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
<i class="fa fa-btn fa-user"></i> Register
</button>
{!! Form::close() !!}
我错过了什么?