Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

pivot 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: #pivot #null #livewire #refresh
ADD COMMENT
Topic
Name
5+8 =