jeudi 1 février 2018

Access ID in Form Request when using resource route with Laravel

I'm working on a multi tenancy app and need to create some slug validation specific to the team (Laravel Spark).

My routes are set up as this for the API endpoint:

Route::prefix('projects/{teamId}')->group(function () {

    Route::resource('posts', 'API\PostController');

});

Using Axios, i'm posting to the following URL:

/projects/1/posts/5

I'm passing in the post info and there is a slug that I need to make sure is unique per team.

In my form request i'm getting the route params:

public function rules()
{
    $teamId = $this->route('teamId');
    $postId = $this->route('id');
}

The issue is, I can get the team id no problem (logging out for testing) but I cannot get the id of the resource... any ideas how to do so?

My last options is to get it from the post parameters...



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire