路线 [admin.distroyDish] 未定义。 (查看:/home/abdalrazag/MyResutrant/resources/views/admin/manager.blade.php)

Route [admin.distroyDish] not defined. (View: /home/abdalrazag/MyResutrant/resources/views/admin/manager.blade.php)

我正在使用 Laravel 7 构建餐厅系统 我制作了去特定路线的表格 我得到了 name route 但它显示错误为 title

经理观点

<form method="post" action="{{route('admin.distroyDish')}}" >
@csrf
<div class="form-group">
    <select class="form-control" name="dish">
    @for ($i = 0 ; $i < count($InetialData['dish']); $i++))
    <option value="{{ $InetialData['dish'][$i]->id }}">
        {{ $InetialData['dish'][$i]->name }}
    </option>
    @endfor
    </select>
</div>
    <input type="submit" name="delete_dish" value="Delete" class="btn btn-danger">
    <br>
</form>

网络路由文件

Route::get('/', function () {
    return view('welcome');
});
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
Route::get('/manager', 'ManagerController@dashboard');
Route::post('/manager', 'ManagerController@addItem');
Route::get('/manager/{id}', 'ManagerController@deleteTable')->name('admin.deleteTable');
Route::post('/manager', 'ManagerController@destroyDish')->name('admin.distroyDish');
Route::post('/manager', 'ManagerController@addIngrediant')->name('admin.addIngrediant');
Route::get('/kitchen', 'KitchenController@index')->name('kitchen.home');
Route::get('/kitchen/{id}', 'KitchenController@submitDish')->name('kitchen.submit.dish');
Route::post('/kitchen', 'KitchenController@addIngrediant')->name('kitchen.addIngrediant');

经理控制器

private function initData()
{
    $InetialData = array(
        'category' => DB::table('Category')->get(),
        'dish' => DB::table('Items')->get(),
        'users' => DB::table('users')->get(),
        'Ingrediant' => DB::table('Ingrediant')->get(),
        'IngrediantHistory' => DB::table('IngrediantHistory')->get()
    );

    return $InetialData;
}

public function destroyDish(Request $request)
{
    DB::table('Items')
        ->where('id', '=', $request->dish)
        ->delete();

    return redirect('/manager')->with('InetialData' , $this->initData());
}

厨房等其他路线正在运作 为什么这条路线不起作用??

据我所知,您有更多路由调用 POST /manager。尝试使用像资源这样的路由:

  1. 获取/实体列表
  2. GET /entities/{entity} 查看
  3. POST /entities 创建
  4. PUT /entities/{entity} 更新
  5. DELETE /entities/{entity} 删除

优雅且易于维护和阅读。

您有重复的路线:

Route::post('/manager', 'ManagerController@addItem');
Route::post('/manager', 'ManagerController@destroyDish')->name('admin.distroyDish');
Route::post('/manager', 'ManagerController@addIngrediant')->name('admin.addIngrediant');

更改端点结构。