public function scopeOfLocale(Builder $builder, $locale = 'en'){
return $builder->where('code', '=', $locale);
}
public function handle($request, Closure $next)
{
Locale::addGlobalScope('locale', function (Builder $builder){
$builder->ofLocale(app()->getLocale());
});
}
public function locales(){
return $this->hasMany(Locale::class);
}
public function current_locale(){
return $this->hasOne(Locale::class)->ofLocale(app()->getLocale());
}
$categories = Category::with('current_locale')->get();
$categories = Category::with('locales')->get();
SELECT p.txt, count(distinct ip.ip)
FROM users u
LEFT JOIN usersip ip
ON u.id = ip.idUsers
LEFT JOIN podrazd p
ON u.podrazd = p.id
group by p.txt
order by p.txt;
SELECT p.txt, ip.ip
FROM users u
LEFT JOIN usersip ip
ON u.id = ip.idUsers
LEFT JOIN podrazd p
ON u.podrazd = p.id
group by p.txt, ip.ip
order by p.txt;
Model::insert([
[row1], [row2], [row3], [row4],
]);
select
users.id, users.name, group_concat(country.country) as visited
from
users
left join user_to_country on user_to_country.user_id = users.id
left join country on user_to_country.country_id = country.id
where u_status = 1
group by users.id, users.name;
Standard SQL disallows references to column aliases in a WHERE clause. This restriction is imposed because when the WHERE clause is evaluated, the column value may not yet have been determined.
select table0.user_id, table1.value_1, table2.value_2
from (select user_id from table group by user_id) as table0
left join table as table1 on table0.user_id = table1.user_id AND table1.type = 'remove' and table1.action_type = 3
left join table as table2 on table0.user_id = table2.user_id AND table2.type = 'give' and table2.action_type = 22
select * from users join (select userid, count(*) as count from fileshare group by userid) as t on users.id = t.userid order by count desc;
select * from users left join (select userid, max(dateupload) as dateupload from fileshare group by userid) as t on users.id = t.userid order by dateupload desc;
`DATE_INSERT` datetime NOT NULL DEFAULT CURRENT_TIMESTAMP
select * from news order by (id > ИД_ТЕКУЩЕЙ НОВОСТИ) desc, id limit 5;