I have two tables and models:
1) Files
2) Visits
using query scope, I can get the total number of visits from particular dates:
public function scopeByDate($query, $start_date, $end_date)
{
return $query->whereHas('visits', function($q) use ($start_date, $end_date)
{
$q->whereBetween('created_at', array($start_date, $end_date));
});
I can do that and this returns all of the files that have visits and these visits are made on a particular date.
As there is a relationship, I can, for each of of these returned files, get the visits by doing $results = Files::ByDate($start, $end)
The problem is that, this returns all of the visits by all of the users on this day. Let's say that I have 10 files and in that day, 5 of them are visited by user 1
and user 2
I want to limit to only showing the visits from user 1
NOTE: Inside the "Visits" there is a field called "user_id"
Is this possible? The users will be contained inside an array. $users = [1, 2, 3, 4]
as an example
from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1Jo2gFi
via IFTTT
Aucun commentaire:
Enregistrer un commentaire