gpt4 book ai didi

mysql - laravel vuex 未从数据库中返回数据

转载 作者:行者123 更新时间:2023-11-29 17:58:24 24 4
gpt4 key购买 nike

我正在使用新编码,我克隆了这个 https://github.com/cretueusebiu/laravel-vue-spa laravel 模板创建一个新项目我创建了另一个表来存储文章,这是我的 Controller 。这不会从数据库返回任何数据,请帮助我。

class ArticleController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return Article::orderBy('id', 'DESC')->get();
}

最佳答案

你的问题是你的路线定义:

Route::resource('/article', 'ArticleController');

这需要是:

Route::resource('article', 'ArticleController');

没有前导斜杠。

当您使用Route::resource时,您实际上是在为GETPOSTPUT定义路由、PATCHDELETE。它与您的模型文章直接相关。

更新

将 web.php 更改为:

Route::resource('article', 'ArticleController');

// this is always the last route in the file
Route::get('{path}', function () {
return view('index');
})->where('path', '(.*)');

关于mysql - laravel vuex 未从数据库中返回数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48606355/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com