Laravel路由中找不到页面错误

时间:2018-08-07 15:31:39

标签: php laravel laravel-5.2

我是laravel的新手,我已经写了一条路线

Route::resource('contract', 'ContractController');
Route::group(['prefix' => 'contract'], function () {
    Route::get('data', 'ContractController@data');
});

我的控制器文件是:

public function data(Datatables $datatables)
{
    $contracts = $this->contractRepository->getAll()
        ->get()
        ->map(function ($contract) {
            return [
                'id' => $contract->id,
                'start_date' => $contract->start_date,
                'end_date' => $contract->end_date,
                'description' => $contract->description,
                'name' =>  '',
                'user' => '',
            ];
        });

    return $datatables->collection($contracts)
        ->addColumn('actions', '@if(Sentinel::getUser()->hasAccess([\'contracts.write\']) || Sentinel::inRole(\'admin\'))
                                    <a href="{{ url(\'contract/\' . $id . \'/edit\' ) }}"  title="{{ trans(\'table.edit\') }}">
                                        <i class="fa fa-fw fa-pencil text-warning"></i> </a>
                                        @endif
                                 @if(Sentinel::getUser()->hasAccess([\'contracts.read\']) || Sentinel::inRole(\'admin\'))
                                 <a href="{{ url(\'contract/\' . $id . \'/show\' ) }}" title="{{ trans(\'table.details\') }}" >
                                        <i class="fa fa-fw fa-eye text-primary"></i> </a>
                                @endif
                                @if(Sentinel::getUser()->hasAccess([\'contracts.delete\']) || Sentinel::inRole(\'admin\'))
                                    <a href="{{ url(\'contract/\' . $id . \'/delete\' ) }}"  title="{{ trans(\'table.delete\') }}">
                                        <i class="fa fa-fw fa-times text-danger"></i></a>
                                 @endif')
        ->removeColumn('id')
        ->escapeColumns( [ 'actions' ] )->make();
}

当我使用网址contract/data运行时,我收到404 not found错误。在控制台中,我也遇到错误

No query results for model [App\Models\Contract].

请帮助我解决问题

1 个答案:

答案 0 :(得分:1)

只需删除Route::resource('contract', 'ContractController');或将其放在Route::group(['prefix' => 'contract'], function () { Route::get('data', 'ContractController@data'); });之后,就像这样:

Route::group(['prefix' => 'contract'], function () {
    Route::get('data', 'ContractController@data');
});
Route::resource('contract', 'ContractController');

您在路由/contract/data上得到404,因为路由器实际上是从contract/{contract}的较高路由定向到ContractController@show中的Route::resource('contract', 'ContractController');