在Laravel中的控制器中创建自定义函数的路由

时间:2019-04-02 06:03:10

标签: laravel

我仍然不明白为什么我不能将刀片指向我在控制器中创建的自定义功能。我创建了这样的路线,

Route::get('/orders/storeInitialItems', 'OrdersController@storeInitialItems')->name('orders.storeInitialItems');

在我的控制器中,我有这个

public function storeInitialItems()
{
    return view('orders.storeInitialItems');
}

但是当我运行页面storeInitialItems.blade.php时,错误似乎调用了控制器的show()函数。

enter image description here

为什么会这样?

更新

完整的ORDERS路线

Route::get('/orders','OrdersController@index')->name('orders.index');
Route::get('/orders/create', 'OrdersController@create')->name('orders.create');
Route::post('/orders', 'OrdersController@store')->name('orders.store');
Route::get('/orders/{order}/edit', 'OrdersController@edit')->name('orders.edit');
Route::post('/orders/{order}', 'OrdersController@update')->name('orders.update');
Route::delete('/orders/{order}', 'OrdersController@destroy')->name('orders.delete');

Route::resource('orders', 'OrdersController');

Route::put('orders/{order}/pub', 'OrdersController@publish')->name('orders.publish');
Route::put('orders/{order}/cancel', 'OrdersController@cancel')->name('orders.cancel');
Route::put('orders/{order}/delivered', 'OrdersController@delivered')->name('orders.delivered');

Route::get('/orders/storeInitialItems', 'OrdersController@storeInitialItems')->name('orders.storeInitialItems');
Route::get('/orders/{order}/delivery', 'OrdersController@viewdeliveryItems')->name('orders.delivery');
Route::get('/orders/acceptDelivery', 'OrdersController@acceptDelivery')->name('orders.acceptDelivery');

1 个答案:

答案 0 :(得分:1)

添加您的orders.storeInitialItems路线

Route::get('/orders/storeInitialItems', 'OrdersController@storeInitialItems')->name('orders.storeInitialItems');

之前

Route::resource('orders', 'OrdersController');

或使用您的storeInitialItems

添加一些额外的路径
Route::get('/orders/storeInitialItems/add-some-extra-path', 'OrdersController@storeInitialItems')->name('orders.storeInitialItems');