hasOne Last updated: 2023-05-29

Let's say  you need to fetch a value in reverse with a table that has data such as addresses for the user and you want to fetch only one address, this is an example of that

hasOne()->make('the address', 'address',AddressResource::class)

Label: the address

method: address in current Model User

class User extends Authenticatable {

 public function address() {
  return $this->hasOne(Address::class);

reference resource is: App\Http\DashResource\AddressResource 

you see that output like belongsTo but you cannot add by hasOne 


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 


full  Example 

//->viewColumns(['email','account_type','account_status']) OR 
// you can add a custom label on specific column 
// Example 
->viewColumns(['email'=>'Email Adderss','account_type'=>__('Email Address'),'account_status'])