关联出错,感觉是不是因为userModel没继续Model的原因呀

来源:7-6 添加评论业务逻辑的实现

李大侠1984

2019-06-02

Relationship method must return an object of type Illuminate\Database\Eloquent\Relations\Relation

namespace App;

use App\baseModel;

class Comment extends baseModel
{
//
public function post(){
$this->belongsTo(‘App\Post’);
}

public function user(){
    $this->belongsTo('App\User');
}

}

在评论里$comment->user->name报这个错

写回答

2回答

李大侠1984

提问者

2019-06-02

不用回答了 少写了return

0
0

李大侠1984

提问者

2019-06-02

<?php

namespace App;

use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class User extends Authenticatable
{
   use Notifiable;

   /**
    * The attributes that are mass assignable.
    *
    * @var array
    */
   protected $fillable = [
       'name', 'email', 'password','avatar'
   ];

   /**
    * The attributes that should be hidden for arrays.
    *
    * @var array
    */
   protected $hidden = [
       'password', 'remember_token',
   ];


}

0
0

Laravel快速开发简书

Laravel最新特性结合Mysql异步消息队列、ElasticSearch搜索引擎、Debugbar调试利器开发简书

1218 学习 · 613 问题

查看课程