Api: Laravel 5.5 Resource routing can not bind model

Created on 6 Jan 2018  路  2Comments  路  Source: dingo/api

| Q | A
| ----------------- | ---
| Bug? | no
| New Feature? | yes
| Framework | Laravel
| Framework version | 5.5
| Package version | 2.0.0-alpha1
| PHP version | 7.0.20

Actual Behaviour

I do the following settings in the routing

$api->version('v1', ['namespace' => 'App\Http\Api\V1\Controllers'], function ($api) {
        $api->resource('applys', 'ApplysController');
});

I am on the controller below

public function destroy(Apply $apply)
    {
        return $apply;
    }

My request http://www.demo.com/api/applys/11 Get the structure is null, but in fact there is data
But when I route the following settings, the structure is normal

Route::resource('applys', '\App\Http\Api\V1\Controllers\ApplysController');

And the following is also problematic

$api->version('v1', ['namespace' => 'App\Http\Api\V1\Controllers'], function ($api) {
        $api->get('applys/{applys}', function (\App\Models\Apply $apply) {
                return $apply->id; // The big one here is null
        })
});

Most helpful comment

Adding bindings middleware to route group solve problem

All 2 comments

Laravel 5.6 same issue

Adding bindings middleware to route group solve problem

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cristiammercado picture cristiammercado  路  3Comments

BartHuis picture BartHuis  路  3Comments

jhayiwg picture jhayiwg  路  3Comments

yaoshanliang picture yaoshanliang  路  4Comments

tankhit picture tankhit  路  3Comments