-1

I'm new in Larvel 4.2 here! How do I do a custom error messages in Laravel 4.2? And where do I put these codes? I've been using the defaults and I kind of wanted to use my own.

Pᴇʜ
  • 56,719
  • 10
  • 49
  • 73
BourneShady
  • 955
  • 2
  • 17
  • 36

2 Answers2

1

Did you try something? http://laravel.com/docs/4.2/validation#custom-error-messages

Did you use Google? Check the documentation (official) it has everything. Be less lazy.

$messages = array(
    'required' => 'The :attribute field is required.',
);

$validator = Validator::make($input, $rules, $messages);
Matt Komarnicki
  • 5,198
  • 7
  • 40
  • 92
1

To add to the answer given by slick, here is how you could use it in a real example of a store function inside a controller:

public function store(Request $request)
    {    
        $validator = Validator::make($request->all(), [
            'id1' => 'required|between:60,512',
            'id2' => 'required|between:60,512',
            'id3' => 'required|unique:table',
        ], [
            'id1.required' => 'The first field is empty!',
            'id2.required' => 'The second field is empty!',
            'id3.required' => 'The third field is empty!',
            'id1.between' => 'The first field must be between :min - :max characters long.',
            'id2.between' => 'The second answer must be between :min - :max characters long.',
            'id3.unique' => 'The third field must be unique in the table.',
        ]);

        if ($validator->fails()) {
            return Redirect::back()
                ->withErrors($validator)
                ->withInput();
        }

        //... Do something like store the data entered in to the form
}

Where the id should be the ID of the field in the form you want to validate.

You can check out all the rules you can use here.

James
  • 15,754
  • 12
  • 73
  • 91