Laravel没有返回编辑视图

时间:2018-01-21 08:48:30

标签: php laravel

即时通讯使用laravel 5.5,我在views / back / categories / edit中为编辑类别创建了一个视图 这里是CategoriesController中的编辑功能

 public function edit($id)
    {
        $category = Categories::getall();
        $categories = Categories::find($id);
        return view('back.categories.edit', ['categories' => $categories, 'category' => $category]);
    }

这是我的路线

Route::group(['middleware'=>'admin'],function(){

    Route::get('/dashboard','BackendController@index')->name('backend');
    Route::group(['prefix' => 'categories'], function () {
        Route::any('/show/{id}', ['as' => 'backend.categories.show', 'uses' => 'backend\CategoriesController@show']);
        Route::get('/index', ['as' => 'back.categories.index', 'uses' => 'backend\CategoriesController@index']);
        Route::any('/store', ['as' => 'back.categories.store', 'uses' => 'backend\CategoriesController@store']);
        Route::any('/create', ['as' => 'back.categories.create', 'uses' => 'backend\CategoriesController@create']);
        Route::any('/edit/{id}', ['as' => 'back.categories.edit', 'uses' => 'backend\CategoriesController@edit']);
        Route::any('/update', ['as' => 'back.categories.update', 'uses' => 'backend\CategoriesController@update']);
        Route::any('/destroy/{id}', ['as' => 'back.categories.destroy', 'uses' => 'backend\CategoriesController@destroy']);
    });

});

我的编辑按钮

    <a href="{{ url('back/categories/edit/'.$category->cat_id) }}" class="btn btn-success btn-sm">
<span class="fa fa-edit"></span> edit</a>

当我点击编辑按钮时,它返回的页面未找到&#34;抱歉,找不到您要查找的页面。&#34;文字和网址:&#34; back / categories / edit / 4&#34;

3 个答案:

答案 0 :(得分:1)

由于您的路线已命名,因此您可以使用route()帮助程序构建工作网址:

{{ route('back.categories.edit', ['id' => $category->cat_id]) }}

答案 1 :(得分:0)

从您的路线定义中,您的网址看起来像/categories/edit/{id}

对于模板中的链接,我建议使用route辅助函数,该函数采用路径名称或采用action的{​​{1}}方法

另请参阅资源控制器

controller@method可以替换您的整个路线定义

https://laravel.com/docs/5.5/controllers#resource-controllers

答案 2 :(得分:0)

您错过了back群组前缀的categories部分。

Route::group(['prefix' => 'back/categories'], function () {

这符合您的路线。