【发布时间】:2021-10-08 13:55:06
【问题描述】:
我正在尝试为我用作 ResourceController 的 Controller 类创建自定义函数。 我这样做是因为我只想更新 1 个字段,但我想保留现有的更新功能用于其他事情。
正如人们所说,我已经尝试将它放在 api.php 中的资源之前,但仍然没有好处。
Route::put('/post/reorder/{id}', 'PostController@reorder');
Route::resource('/post', PostController::class);
这是控制器中的代码
public function reorder(Request $request, $id){
$post = Post::findOrfail($id);
...
另外,在运行 php artisan route:list 时会显示此错误。
Illuminate\Contracts\Container\BindingResolutionException
Target class [PostController] does not exist.
这是 VUE 中调用它的代码
export const API_URL = "http://localhost:8000/api/post";
axios
.put(API_URL + `/reorder/${item.id}`, {
// title: item.title,
// path: item.path,
// description: item.description,
order: newIndex,
})
当我运行它时,它给出了内部服务器错误 500
当我使用资源给我的默认功能时它可以工作,我只是不想输入我不想更改的字段。
那么我做错了什么?
【问题讨论】:
标签: mysql laravel vue.js laravel-8