belongsTo Last updated: 2023-05-29
To start using one item that is linked to another resource through the custom field in the current Model
Let's give a quick example
belongsTo()->make('Group', 'admingroup',AdminGroups::class)
Label : Group
the relation method is: admingroup
the reference resource is : App\Dash\Resources\AdminGroups
in Index Page
in Show Page
In create and edit page
you can ran other query in the same relation model
this method works on belongsTo , belongsToMany relationship
example:
belongsTo()->make('Group', 'admingroup',AdminGroups::class)
->query(function ($model) {
// full_power , owner , moderate
return $model::whereIn('admin_type', ['owner', 'moderate']);
})
You Can Make Inline relation button to Create A new record
just add :-
belongsTo()->make('Group', 'admingroup',AdminGroups::class)
->inlineButton() // parameter bool true or false | default is true
// to disable inline button set ->inlineButton(false)
Example:-
in Started Version 1.0.62 you can provide a new Method viewColumns
to view custom columns in datatable index and sub resource in show page
working with belongsTo,hasOne
functions
//->viewColumns(['email','account_type','account_status']) OR
->viewColumns('email','account_type','account_status')
full Example
belongsTo()->make('User','user',Users::class)
//->viewColumns(['email','account_type','account_status']) OR
->viewColumns('email','account_type','account_status')
// you can add a custom label on specific column
// Example
->viewColumns(['email'=>'Email Adderss','account_type'=>__('Email Address'),'account_status'])