I think you could move the find method in the repository also, as an update will most likely be combined with a find. What I usually do is the following (just be sure to set either a guarded or fillable property on you Resident model):
public function find($id)
{
return Residents::find($id);
}
public function update($id, $input)
{
$resident = $this->find($id);
$resident->fill($input);
return $resident->save();
}
Then all you have to do in your controller:
public function update($id)
{
$this->resident->update($id, $input);
// Redirect...
}
You might want to add some validation in there before saving though.
Hope that helps!
example
public static function validate($input) {
$newStudent = array( 'name' => Input::get('name'), 'number'=>Input::get('number'), 'location'=>Input::get('location'), 'phone'=>Input::get('phone'), );
$rules = array(
# validation code
'name' => 'Required|Min:3|Max:80|Alpha',
'number'=> 'Required|Between:3,64',
'location'=> 'Required|Min:3|Max:80|Alpha',
'phone'=>'Required|Between:3,64',
);
$validation = Validator::make($newStudent, $rules);
if($validation->fails()){
return Redirect::to('new')
->with_errors($validation)
->with_input();
}
return Redirect::back();
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community