select sum(number), country_id from table group by country_id;
select sum(number), city_name, country_id from table group by country_id;
public function project(): HasOne
{
$instance = $this->newRelatedInstance(Project::class);
$relation = new HasOne($instance->newQuery(), $this, DB::raw('project_user.user_id'), $this->getKeyName());
return $relation->leftJoin('project_user', 'project_user.project_id', '=', 'projects.id');
}
Model::insert([
[row1], [row2], [row3], [row4],
]);
public static function fromRequest(FormRequest $request): static
{
$data = $request->validated();
$properties = (new \ReflectionClass(self::class))->getProperties(\ReflectionProperty::IS_PUBLIC);
foreach ($properties as $property){
if(!isset($data[$property->name])){
$data[$property->name] = $property->getDefaultValue();
}
}
return new static(...$data);
}
public function __invoke($attribute, $value, $fail)
{
$dishesRequest = collect($value);
$data = Dishe::whereIn('id', $dishesRequest)->Active()->whereHas('menu', function ($query) {
return $query->where('project_id', $this->project->id)->Active();
})->selectRaw('count(1) as count, sum(price) as sum');
if($data->count != $dishesRequest->count()){
return $fail(__('validation.exists'));
}
# Получаем список блюд по массиву идентификаторов
$totalDishes = $data->sum;
$total = $this->order ? $totalDishes + $this->order->totalPrice : $totalDishes;
if ($total < 1 || $total > 150000) {
return $fail('Сумма заказа должна быть от 1 ₽ до 150 000 ₽');
}
}
SELECT performer."id", performer."user", "portfolio", "rating", "balance", performer."created_at"
FROM performer
INNER JOIN performer_subject ON performer.id = performer_subject.performer_id AND performer_subject.subject_id = :subject_id
where not exists(select 1 from "order" where performer.id = order.performer and order.completed = false)
ORDER BY rating
SELECT performer."id", performer."user", "portfolio", "rating", "balance", performer."created_at"
FROM performer
INNER JOIN performer_subject ON performer.id = performer_subject.performer_id AND performer_subject.subject_id = :subject_id
where not exists(select 1 from "order" where performer.id = order.performer)
ORDER BY rating
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;
DB::table('posts')
->select('*')
->where('id', '>', $getPost->id)
->where('city', '=', $getPost->city)
->where('approve', '=', 1)
->orderByRaw('(id > ?) desc, id asс' , [$getPost->id])
->limit(10)
->get();
php artisan make:policy OrderPolicy
class OrderPolicy
{
use HandlesAuthorization;
public function update(User $user, Order $order)
{
if (!$user->isEmployee()) {
return false;
}
if ($user->id !== $order->user_id) { // остальной кусок ифа не понял - но он должен быть здесь.
return false;
}
return in_array($order->status, [Order::NEW, Order::WORK]);
}
}
class OrderUpdateRequest extends FormRequest
{
public function authorize()
{
return $this->user()->can('update', $this->order);
}
}
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.
update "notifications"
set "is_read" = 1,
"updated_at" = 2023 - 02 - 01 12:26:05
from ( select id from "notifications" where “client_id” = 126473 and "notifications"."client_id" is not null order by id for update) as t
where "notifications"."id" = t.id ;