I'm trying to update some data with image. The other data is updated but the image still not updated. here's my code
route
Route::get('film/{idFilm}/edit', array('as' => 'film.edit', 'uses' => 'FilmController@edit'));
Route::post('film/{idFilm}/update', array('as' => 'film.update', 'uses' => 'FilmController@update'));
controller
public function edit($idFilm)
{
$film = Film::findOrFail($idFilm);
$genre = Genre::lists('namaGenre', 'idGenre');
if (is_null($film))
{
return Redirect::to('film');
}
return View::make('pengelolaan.film.editfilm', compact('film','genre'));
}
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($idFilm)
{
$rules = array(
'judulFilm' => 'required',
'durasi' => 'required|numeric',
'keterangan' => 'required',
'idGenre' => 'required'
);
$validation = Validator::make(Input::all(), $rules);
if ($validation->fails())
{
return Redirect::to('film/' . $idFilm . '/edit')
->withErrors($validation)
->withInput()
->with('message', 'There were validation errors.');
}
else
{
$films = Film::find($idFilm);
$films->judulFilm=Input::get('judulFilm');
$films->durasi=Input::get('durasi');
$films->keterangan= Input::get('keterangan');
$films->idGenre= Input::get('idGenre');
if(Input::hasFile('foto'))
{
$file=Input::file('foto');
$file->move('img',$file->getClientOriginalName());
$filename=$file->getClientOriginalName();
$films->foto = $filename;
$films->save();
}
else
{
$films->save();
}
Session::flash('message', 'Data Berhasil Diubah');
return Redirect::to('film');
}
}
view
<div class="form-group">
<div class="col-lg-6">
</div>
</div>
<div class="form-group">
<div class="col-lg-6">
</div>
</div>
<div class="form-group">
<div class="col-lg-6">
</div>
</div>
<div class="form-group">
<div class="col-lg-6">
</div>
</div>
<div class="form-group">
<div class="col-lg-6">
</div>
</div>
</br>
<div class="form-group">
<div class="col-lg-6">
<a class="btn btn-default " href="">Batal</a>
There's no error so i don't know whats wrong with it. Can someone please tell me what's wrong? Thanks in advance
via Sekar Anindya