vendredi 2 juin 2017

Laravel Rest API: How to implement a function for post request

I am trying to implement a REST API for basic CRUD operations with Laravel 5.4 I have a post method as below.

public function storeReport(StoreReportRequest $request){

    $inputs = $request->only('company_name',
                             'company_experience',
                             'service_start_time',
                             'service_end_time',
                             'latitude',
                             'longitude',
                             'additional_info',
                             'user_id'
                             );

    //save image content to folder and image name to database
    $image = $request->file('picture');
    $fileName = $image->getClientOriginalName();
    $image->storeAs('images', $fileName);
    $inputs['picture_url'] = $fileName;

    $report = Report::create($inputs);

    return 'success';
}

I do not have any problems with storing the data.I have some rules for validation and i do validation via StoreReportRequest class.What i want to learn is how can i handle the response after POST request. For example if validation fails or any exception occurs what should i return and how it should be. I have done some research but couldnt find any proper answers. Any help would be appreciated.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2qH4cHi
via IFTTT

Aucun commentaire:

Enregistrer un commentaire