Eloquent 模型在 Laravel 中不起作用

Eloquent Model doesn't work in Laravel

我创建了我的第一个模型,运行浏览器中的正确路径并出现错误:

Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_UNKNOWN)
Call to undefined method Post::all()

为什么会这样?我正在学习 laravel 课程,老师对未定义的方法没有问题 :(

我通过 artisan 生成模型:

php artisan generate:model Post

我的控制器:

public function listing()
    {
       $posts = Post::all();
       return View::make('post.listing', compact('posts'));
    }

我的模特:

class Post extends Eloquent {

}

我的看法:

@extends('layouts.default')

@section('content')
@foreach($posts as $post)
    <h1>{{{ $post->title }}}</h1>
@endforeach

@stopassola 

我该如何解决这个问题?当然,我在数据库中有 table 个命名的帖子。

试试这个

public function listing()
{
   $posts = \App\Post::all();
   return View::make('post.listing', compact('posts'));
}

干杯!

我使用了 composer dumpautoload,发现有 2 个 类 名为 Post。

问题已解决。