samedi 1 avril 2017

Laravel Spark API call validation not returning errors on fail but showing login page

I am working on a Laravel API and have a resource route for adding events.

I have added a form request for validation, but when using Postman with a correct API key set the validation failure will return a 200 status and show the login page as if unauthorised.

API route:

Route::group([
    'middleware' => 'auth:api',
    'prefix' => 'v1'
], function () {
    Route::resource('events', 'Api\V1\EventController');
});

Form request:

<?php

    namespace App\Http\Requests;

    use Illuminate\Foundation\Http\FormRequest;

    class StoreEvent extends FormRequest
    {

    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        return [
            'name' => 'required'
        ];
    }
}

In my controller:

public function store(StoreEvent $request)
{
    return Event::create([
        'user_id' => Auth::user()->id,
        'name' => $request->name,
    ]);
}

If I have a name field set in the request, it correctly adds a value but not having a name field returns the login page.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire