Php 调用未定义的方法Posts::newQuery()

Php 调用未定义的方法Posts::newQuery(),php,laravel,Php,Laravel,为什么我会犯这个错误?我怎样才能解决这个问题呢?我正在尝试检索用户的帖子 User.php模型 看法 Laravel在配置上使用了很多约定,因此请确保您的约定是正确的 如果您的类是Posts,请确保您的文件名为Posts.php。你的问题提到了两个方面 您对用户的关系方法是后大写的,但您是以$user->Post小写形式访问它的。确保您的命名和用法一致。错误消息中应该有提示,提示错误发生在哪个文件的哪一行。我在您给定的代码中找不到newQuery。return new HasMany$insta

为什么我会犯这个错误?我怎样才能解决这个问题呢?我正在尝试检索用户的帖子

User.php模型

看法


Laravel在配置上使用了很多约定,因此请确保您的约定是正确的

如果您的类是Posts,请确保您的文件名为Posts.php。你的问题提到了两个方面


您对用户的关系方法是后大写的,但您是以$user->Post小写形式访问它的。确保您的命名和用法一致。

错误消息中应该有提示,提示错误发生在哪个文件的哪一行。我在您给定的代码中找不到newQuery。return new HasMany$instance->newQuery,$this$instance->getTable..$foreignKey,$localKey;}我想是这样吧?
<?php

use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;

class User extends Eloquent implements UserInterface, RemindableInterface {

    use UserTrait, RemindableTrait;

    /**
     * The database table used by the model.
     *
     * @var string
     */
    protected $table = 'users';

    /**
     * The attributes excluded from the model's JSON form.
     *
     * @var array
     */
    protected $hidden = array('password', 'remember_token');


    public function Posts()
    {
            return $this->hasMany('Posts');
    }
}
<?php 

    Class Posts extends Eloquent 
    {
        public function User()
        {
                return $this->belongsTo('User');
        }
    
public function newPost($id)
    {
        $user = User::findOrFail($id);

        $post =  new Posts();
        $post->title = Input::get('title');
        $post->content = nl2br(Input::get('content'));

        $user->post()->save($post);

        return Redirect::route('profile', array('id' => $user->id));

    }
@section('post')
    <section>
        @foreach($users->posts as $post)
        <p>{{$user->name}} says...</p>
        <blockquote>{{$post->content}}</blockquote>
        @endforeach
    </section>
        
@stop