mercredi 13 novembre 2019

Why error handling is not working in Laravel

I have set the debug to ture on .env file. Added the expectations correctly but when i am passing invalid or not exist in my database its showing me 404 error where I put the custom error handling value. Here is my code. (also I put "Use Expectation;" on top so no need of \Expectation)

public function show($id)
    {
        //only one author with id
        try
        {
            $event = Event::with('eventCategory')->findOrFail($id);
            return new EventsResource($event);
        //return one author
        }
        catch(Expectation $e)
        {   
            report($e);
            return response()->json(['status'=> false, 'message'=>'invalid data'],200);

        }

    }


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire