#1506·api

Laravel 5.5 Resource routing can not bind model

Author: myloveGyCreated Jan 6, 2018Updated Nov 18, 2022
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
        })
});