The goal to achieve is to have controller actions that look like that (example a store action)
public function store(){
$input = Input::only('username', 'blahblah', ...);
$user = new User($input);
if(!$user->save()){
// Redirect to the form page with data and errors
return Redirect::route('users.create')
->withInput()
->withErrors($user->getErrors());
}
// Redirect to show with a success message
return Redirect::route('users.show', $user->id)
->with('notice', 'User successfully created');
}
You can see that your user model can perform validation on save and store the resulting error.
$validator = Validator::make(Input::all(), User::$rules)
if($validator->fails() {
return Redirect::back()->withInput()->withErrors($validator);
}
$user = User::create(Input::all);
You will have to set the protected $fillable = []; or protected $guarded = []; in User model
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community