Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PHP

only get selected value from has many ralation laravel

class User extends Model {
  public function products(): hasMany {
      return $this->hasMany('AppProduct');
  }
}
$user = User::findOrFail($user_id);
/* user_id is must important is hasMany Relationship */
$user_products = $user->products()->select('product_name', 'category',
                                           'user_id')->get();
 
PREVIOUS NEXT
Tagged: #selected #ralation #laravel
ADD COMMENT
Topic
Name
5+6 =