Php get()函数在laravel 8更新版本上不起作用
这是ArticlesController代码Php get()函数在laravel 8更新版本上不起作用,php,laravel,Php,Laravel,这是ArticlesController代码 <?php namespace App\Http\Controllers; use App\Models\Article; use Illuminate\Http\Request; class ArticlesController extends Controller { public function index() { $articles = Article::latest()->get(); return v
<?php
namespace App\Http\Controllers;
use App\Models\Article;
use Illuminate\Http\Request;
class ArticlesController extends Controller
{
public function index()
{
$articles = Article::latest()->get();
return view('articles.index', ['articles' => $articles]);
}
public function show($id)
{
$article = Article::find($id);
return view('articles.show', ['article' => $article]);
}
}
这是layout.blade.php代码
<li class={{Request::path() === 'articles' ? 'current_page_item' : ''}}><a href="/articles"
accesskey="4"
我尝试了很多不同的方法,但在laravel 8中它不起作用。您在模型上定义了名为latest
的方法吗?是的,您也可以在错误图片上看到它。显示您创建的名为latest
的方法,因为该方法已经在Eloquent Builder上定义。。。我们无法知道您在创建的方法中做了什么
public function index()
{
$articles = Article::query()->latest()->get();
return view('articles.index', ['articles' => $articles]);
}
public function index()
{
$articles = Article::query()->latest()->get();
return view('articles.index', ['articles' => $articles]);
}