vendredi 8 mars 2019

Laravel Test api Post MethodNotAllowedHttpException

Hello I'm using Laravel 5.5 and have in my test

public function testCreate()
    {
        $userAdmin = factory(User::class)->create();
        $roleAdmin = Role::where('name', 'admin')->first();

        $userAdmin->roles()->attach($roleAdmin);

        $this->actingAs($userAdmin)->post('/api/object/create')
            ->assertJson(["success"=>true]);
    }

In my routes:

Route::group(['middleware' => 'auth:api'], function () {
   Route::group(['prefix'=>'object'], function(){
      Route::post('create', 'ObjectController@create')->middleware('can:create,App\Models\Object');
   });
});

But when I run my test return:

Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException

I have already tried to clear my route with:

php artisan route:cache

And with:

$this->actingAs($userAdmin, 'api')->post('/api/object/create')

And

$this->actingAs($userAdmin, 'api')->post('/object/create')

But it doesn't work. What I'm wrong?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire