Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

laravel get data in pivot table

// In model User.php, add withPivot; for ex :
public function customer(){
    return $this->belongsToMany('role')
                ->withPivot('type'); // 'type' is from pivot table user_role
}

// then access the field with ->pivot; for ex:
$current_user->customer->pivot->type
 
PREVIOUS NEXT
Tagged: #laravel #data #pivot #table
ADD COMMENT
Topic
Name
6+5 =