Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/230.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php get()函数在laravel 8更新版本上不起作用_Php_Laravel - Fatal编程技术网

Php get()函数在laravel 8更新版本上不起作用

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

这是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 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]);
    }