Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

BelongsToMany relations pivot fields are null in Livewire refresh

# BelongsToMany relations pivot fields are null in Livewire refresh
# just re-hydrate it, example:

// in Model
public function role(){
	return $this->belongsToMany(Role::class, "tbl_user_has_roles", "user_id", "role_id")->withPivot("some_column");
}

// in livewire component
public function hydrate(){
	$this->userRole = User::with(["role"])->where('id', $this->id)->first()->role;
}
Source by github.com #
 
PREVIOUS NEXT
Tagged: #BelongsToMany #relations #pivot #fields #null #Livewire #refresh
ADD COMMENT
Topic
Name
8+1 =