Support the ongoing development of Laravel.io →
Database Eloquent IOC
Last updated 2 years ago.
0

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!

Last updated 2 years ago.
0

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();
Last updated 2 years ago.
0

@stidges Legend, worked a treat thank you.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

lstables lstables Joined 5 Jan 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.