1 year agoby Salman Zafar

How to create relationship with user table while developing a package?


how can i define relationship with user table while creating a Laravel package? Suppose i've a table to links and i want to add it relationship with existing user table in laravel ? How can i achieve that?



Sarthak Shrivastava replied 1 year ago


Let user model is always App\User on every laravel. Just create user relation in your package as you normally do.

If you want dynamic user model, then in your package config file you need to set for user model like this

return [
	'models'  => [
		'user' => App\User::class,

then on your other model, then get this from your your config file.

public function user()
		return $this->belongsTo(config('packageName.models.user'), 'user_id');
Ask Question
Most Visited