Hi, I'm new to Laravel.
I use the Laravel 5.2 default authentication; in App/User.php we have the default:
namespace App;
use Illuminate\Foundation\Auth\User as Authenticatable;
class User extends Authenticatable
{
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
}
Then, for users, I want to set a relation like:
public function posts( )
{
return $this->hasMany('App\Post');
}
But to do this I need to extend Model and not Authenticatable like the user class above; so the question is: can I insert the relation inside the "class User extends Authenticatable" (maybe dependency injection?), and if yes in wich way? Thanks!
Illuminate\Foundation\Auth\User extends model - so you should be able to include the relation as you suggest out of the box.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community