Laravel 直接发布到资源索引

Har*_*ist 1 php resources controller request laravel

我有一个,希望很小,问题。我需要能够直接发布到我的索引。现在我正在使用资源控制器:

Route::resource('appointments', 'AppointmentsController');
Run Code Online (Sandbox Code Playgroud)

而且我希望能够使用下拉列表从我的资源控制器更新我的索引视图以将值发布到我的索引。所以我可以像这样使用这些值:

public function index(Request $request)
Run Code Online (Sandbox Code Playgroud)

直到此时,我使用不同的路由来发布,然后重定向到我的约会.index 路由,依此类推。但那是愚蠢的。我希望仍然能够使用我的资源控制器,否则我需要创建很多路由(因为我使用了一堆资源控制器并且我需要能够直接发布到所有这些的索引)。

解决此问题的最有效方法是什么?我确实尝试使用 url 打开我的表单,然后在末尾添加一个斜杠,但这并没有奏效。

Fab*_*nes 6

It's quite simple, just create your Resource controller without the store route, like this:

Route::resource('appointments', 'AppointmentsController', ['except' => ['store']]);
Run Code Online (Sandbox Code Playgroud)

Then add your route before the resource declaration, something like this:

Route::post('appointments', 'AppointmentsController@index');
Route::resource('appointments', 'AppointmentsController', ['except' => ['store']]);
Run Code Online (Sandbox Code Playgroud)