Я пытаюсь получить комментарий и пользователя этого комментария. У меня есть следующие отношения между пользователем и комментарием.
Это то, что я пытаюсь
$ users = Comment :: with ('user') -> get ();
Но я получаю
Class 'User' not found
Я не уверен, что не так с моим кодом.
Любая помощь приветствуется.
Комментарий
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use App\User;
use App\Event;
class Comment extends Model
{
// Table Name
protected $table = 'comments';
//primary key
public $primaryKey = 'id';
protected $fillable = ['user_id', 'event_id', 'comment', 'deleted_at'];
public function user()
{
return $this->belongsTo('User');
}
Пользователь
<?php
namespace App;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Tymon\JWTAuth\Contracts\JWTSubject;
class User extends Authenticatable implements JWTSubject
{
use Notifiable;
protected $fillable = [
'name', 'email', 'password',
];
protected $hidden = [
'password', 'remember_token',
];
public function getJWTIdentifier()
{
return $this->getKey();
}
public function getJWTCustomClaims()
{
return [];
}
public function setPasswordAttribute($value)
{
return $this->attributes['password'] = bcrypt($value);
}
}