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

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.

Last updated 2 years ago.
0
$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

Last updated 2 years ago.
0

Thanks that helped a lot.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

2akurate 2akurate Joined 13 May 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.