mercredi 4 mai 2016

Laravel request service return json

When you validate your data using a request service how do you return the the errors in json format like e.g.

return response->json(array("errors' => true, 'errors' => $errors));

Request Service:

<?php

namespace App\Http\Requests;

use App\Http\Requests\Request;
use Auth;

class MyRequest extends Request
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    protected $action;

    public function authorize()
    {
        if(Auth::check()) {
            return true;            
        }        
    }

    public function validate() {
        return parent::validate();
    }

    public function all()
    {

    }

    public function messages()
    {
    }    

    public function rules()
    {               

    }
}

Controller:

public function store(MyRequest $request) {
    $mymodel = new MyModel();
    $mymodel->title = 'test';
    $model->save();
}



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

Aucun commentaire:

Enregistrer un commentaire