laravel eloquent hasmany select
$data = AppUser::with('articles:id,title,user_id')->get();
// user_id is important in hasmay relationships
laravel eloquent hasmany select
$data = AppUser::with('articles:id,title,user_id')->get();
// user_id is important in hasmay relationships
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();
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us