I'm using Eloquent ORM in laravel. there is 2 model, User and Trans. User hasMany Trans, and Trans belongsTo User. The problem is when i'm using query where, it doesnt work
i tried using ->get() in the last code, it still doesnt work. i tried using ->all() in the last code it still doesnt work. i tried whereIn, it still doesnt work
Model User
public function trans(){
return $this->hasMany('App\Trans', 'user_id');
}
Model trans
public function user ()
{
return $this->belongsTo('App\User','user_id');
}
Controller
$trans = Auth::user()->trans->where('date', $date);
I want the output is based on query where the date is based on user input, when i delete ->where , it works and the output like this
Collection {#797 ▼
#items: array:13 [▼
0 => Trans {#783 ▶}
1 => Trans {#784 ▶}
2 => Trans {#785 ▶}
3 => Trans {#786 ▶}
]
}
from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2Tw7knf
via IFTTT
Aucun commentaire:
Enregistrer un commentaire