lundi 14 novembre 2016

How to send error validation message from controller to the view in Laravel 5.2

Code in my PagesController.php

public function postIndex(Request $request){

    $this->validate($request, [
            'name' => 'required',
            'email' => 'required|email',
            'phone' => 'min:3',
            'message' => 'min:10',
    ]);

    $data = array(
            'name' => $request->name,
            'email' => $request->email,
            'phone' => $request->phone,
            'bodyMessage' => $request->message,
            'subject' => 'Some subject',
    );

    Mail::send('emails.contact', $data, function($message) use ($data){
        $message->from($data['email'], "Hello");
        $message->to('some_user@gmail.com');
        $message->subject($data['subject']);
    });

    Session::flash('success', 'Email was sent');

    return redirect('/');
}

In the $request are data from form inputs. If some errors are in validate view is redirect to '/'. My question is hot to handle error message in view ?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire