Laravel 5 Builder.php第2345行中的BadMethodCallException:调用未定义的方法Illumb\Database\Query\Builder::notes()

Laravel 5 Builder.php第2345行中的BadMethodCallException:调用未定义的方法Illumb\Database\Query\Builder::notes(),laravel-5,Laravel 5,我在学习laracats.com上的laravel从头开始的教程时遇到上述错误, 下面是完整的错误消息 哎呀,好像出了什么事。 Builder.php第2345行中的1/1 BadMethodCallException:调用未定义的方法Illumb\Database\Query\Builder::notes() 我的NotesController如下所示 namespace App\Http\Controllers; use App\Card; use App\Note; use Illum

我在学习laracats.com上的laravel从头开始的教程时遇到上述错误, 下面是完整的错误消息

哎呀,好像出了什么事。 Builder.php第2345行中的1/1 BadMethodCallException:调用未定义的方法Illumb\Database\Query\Builder::notes()

我的NotesController如下所示

 namespace App\Http\Controllers;

use App\Card;
use App\Note;
use Illuminate\Http\Request;


class NotesController extends Controller
{
    public function store(Request $request, Card $card)
    {


        $note = new Note;

        $note->body = $request->body;
        $note->notes()->save($note);

        return back;


}
}
 namespace App;

use Illuminate\Database\Eloquent\Model;

class Card extends Model
{
   public function notes()
   {
    return $this->hasMany(Note::class);
   }

   public function path()
   {
    return '/cards/'.$this->id;
   }
}
卡片型号如下

 namespace App\Http\Controllers;

use App\Card;
use App\Note;
use Illuminate\Http\Request;


class NotesController extends Controller
{
    public function store(Request $request, Card $card)
    {


        $note = new Note;

        $note->body = $request->body;
        $note->notes()->save($note);

        return back;


}
}
 namespace App;

use Illuminate\Database\Eloquent\Model;

class Card extends Model
{
   public function notes()
   {
    return $this->hasMany(Note::class);
   }

   public function path()
   {
    return '/cards/'.$this->id;
   }
}

根据提示,您正在尝试将便条保存到卡中。所以你应该使用
$card->notes()->sav‌​e(附注)而不是
$note->notes()->保存($note)

请添加您的NotesController是否已迁移表?与您雄辩的模型相关联的名称是什么:
Notes
Note
?这个模型存在吗?您可以使用:
php artisan make:model Note
php artisan make:model Notes
创建它。试着在命令行上运行:
composer dump autoload
。@Poiz我使用了php artisan make:modelNote@RavishaHesh我在上面添加了NotesController,我也面临相同的错误,而不是_调用('notes')。任何错误都发生在Builder->_调用('appends',array(null))上。您是否定义了notes()卡型号上的关系?请添加卡型号也请参见上面的卡型号您的卡型号看起来正常,您从
$Card->notes()->sav中得到了什么错误‌​e(附注)Builder.php第2345行中的错误是BadMethodCallException:调用未定义的方法Illumb\Database\Query\Builder::sav‌​e()