关联查询一致报错,不得已来SF麻烦各位大神帮我解答。报错内容ErrorExceptionin777fb9d9b961f2b2453d93297ba8a847line15:Tryingtogetpropertyofnon-object(View:/home/millyn/www/x.x/resources/views/NewHome.blade.php)我的对应文件如下Avatar.phpuseIlluminate\Database\Eloquent\Model;classAvatarextendsModel{publicfunctionarticle(){return$this->hasMany('App\Article');}}Article.phpuseIlluminate\Database\Eloquent\Model;classArticleextendsModel{//publicfunctionavatar(){return$this->belongsTo('App\Avatar');}}Controller.phppublicfunctionindex(){$articles=Article::with('avatar')->latest()->paginate(8);returnview('NewHome',compact('articles'));}NewHome.blade.php @foreach($articlesas$page)title}}"href="{{URL('news/'.$page->id)}}"> {{$page->title}}
title}}"href="{{URL('news/'.$page->id)}}"> avatars_id->url}}"alt=""width="180px">
@endforeach
{!!$articles->render()!!}article_table.phppublicfunctionup(){Schema::create('articles',function(Blueprint$table){$table->increments('id');$table->string('title');$table->text('body')->nullable();$table->string('site')->nullable();$table->integer('avatars_id')->unsigned();;$table->integer('user_id');$table->string('nike')->nullable();$table->timestamps();$table->foreign('avatars_id')->references('id')->on('avatars')->onDelete('cascade');});}avatars_table.phppublicfunctionup(){Schema::create('avatars',function(Blueprint$table){$table->increments('id');$table->string('title');$table->string('url');$table->text('path');$table->timestamps();});}我不知道是哪里有问题,不管怎么弄都是报错..希望大神帮忙看看.谢谢了.偶然的你浏览 306回答 22回答
湖上湖
你可以dd($articles)来看看,相信在relations这一个上面会是null,总感觉你的relationship声明好奇怪随时随地看视频慕课网APP相关分类