我正在使用新编码,我克隆了这个 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
时,您实际上是在为GET
、POST
、PUT
定义路由、PATCH
和 DELETE
。它与您的模型文章
直接相关。
更新
将 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/