hasMany Last updated: 2023-08-15
You have a user and you want to prepare all the data that he owns and view it
In such a situation you need to use the hasMany relationship
Now after we logically agreed , let dash simplify this process for you
After preparing your model , all you have to do is to use the method
hasMany()->make('Articles', 'articles', Articles::class)
or
hasMany()->make('Articles', 'articles', Articles::class)->use('user')
// this method ->use('user') if you are mention the belongsTo relationShip in Article Model to auto select parent value
example
class Article extends Model
{
public function user(){
return $this->belongsTo(User::class);
}
}
Label: Articles
method: articles
reference resource is: App\Dash\Resources\Articles
your current model User
class User extends Authenticatable {
public function articles() {
return $this->hasMany(Article::class); // by user_id column in articles table
}
}
You will also see the data show page here
you can use the hide Options with all relationships in index & show page