Route [dashboard.update]未定义。而它是在routes(routs / web.php)文件中定义的

时间:2017-05-21 16:27:22

标签: php laravel routes

这是我的laravel路由文件代码和所有其他路径工作得很好,但更新'路线给出错误“路线[dashboard.update]未定义' 这是路线代码

Route::group(['middleware' => 'auth', 'prefix' => 'dashboard'],function (){

// get routes
Route::get('/', 'HomeController@index')->name('dashboard.index');
Route::get('add', 'HomeController@addNotice')->name('dashboard.add');
Route::get('{id}/edit', 'HomeController@editNotice')->name('dashboard.edit');
Route::get('{id}', 'HomeController@showNotice')->name('dashboard.show');

// post routes
Route::post('add', 'HomeController@storeNotice')->name('dashboard.store');
Route::post('{id}','HomeController@updateNotice')->name('dashboard.update'); //error here
Route::post('{id}', 'HomeController@deleteNotice ')->name('dashboard.delete');
});

这是HomeController返回的视图代码

<form action="{{ route('dashboard.update',['noticeId' => $noticeId->id]) }}" method="POST" style="padding-left: 10px; padding-right: 10px;">
            {{ csrf_field() }}
            <div class="row">
                <div class="form-group">
                    <input type="text" class="form-control" name="noticeTitle" placeholder="Give Title to Notice" value="{{ $noticeId->title }}">
                </div>
            </div>

            <div class="row">
                <div class="form-group">
                    <textarea name="noticeBody" cols="30" rows="8" class="form-control" placeholder="Add Notice Details Here" style="resize: none">{{ $noticeId->body }}</textarea>
                </div>
            </div>

            <div class="row">
                <div class="form-group">
                    <input type="submit" name="editNotice" value="Save Changes" class="btn btn-info btn-block btn-sm">
                    <input type="hidden" name="_method" value="PUT">
                </div>
            </div>
        </form>

2 个答案:

答案 0 :(得分:0)

将您的路线类型更改为PUTPATCH

Route::patch('{id}','HomeController@updateNotice')->name('dashboard.update');

这是你的表格

{!! method_field('PATCH') !!}

此处的错误是因为您的删除路由正在覆盖更新路由,因为它们的类型和路径相同。通常,对于删除路由,您应该使用“DELETE”方法。

答案 1 :(得分:0)

Route::post('{id}','HomeController@updateNotice')->name('dashboard.update');

Route::put('{id}','HomeController@updateNotice')->name('dashboard.update');