mercredi 30 mars 2016

doesnot show any validation error messages in laravel5

I have used this function in controller to store the records of the users with validations. The data is not stored if the validation is not met but it doesnot show any validation error message.

public function store()
  {

        $input = Input::all();
        $validation = Validator::make($input, User::$rules);

        if ($validation->passes())
        {
            User::create($input);

            return Redirect::route('users.index');
        }

        return Redirect::route('users.create')
            ->withInput()
            ->withErrors($validation)
            ->with('message', 'There were validation errors.');
  }

I have the model:

<?php
namespace App;

class User extends BaseModel{

    protected $fillable = [
        'name', 'email', 'password', 'phone'
    ];


    protected $hidden = [
        'password', 'remember_token',
    ];

  public static $rules = array(
    'name' => 'required|min:5',
    'email' => 'required|email');
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire