public function scopePayedOrders(Builder $builder):Builder{
return $builder->whereRaw('(select sum(incomes.sum) from incomes where incomes.order_id = orders.id) > (select sum(products.sum) from products where incomes.order_id = orders.id)');
}
$items = Orders::payedOrders()->get();
Product::whereDoesntHave('collections', function (Builder $query) {
return $query->whereIn('id', [15]);
})->orderBy('created_at', 'desc')->limit(4)->get();
class OrderUpdateRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize(): bool
{
return $this->order->canChangeStatus($this->get('status'))&&$this->order->canUpdate();
}
}
switch ($this->getMethod())
{
case 'PATCH':
return [
'table_id' => ['numeric', 'exists:tables,id'],
'user_id' => ['numeric', 'exists:users,id'],
'status' => ['string', 'in:'. Order::NEW.','.Order::WORK.','.Order::CLOSE.','.Order::PAID],
];
case 'PUT':
return [
'table_id' => ['required', 'numeric', 'exists:tables,id'],
'user_id' => ['required', 'numeric', 'exists:users,id'],
'status' => ['required', 'string', 'in:'. Order::NEW.','.Order::WORK.','.Order::CLOSE.','.Order::PAID],
];
}
class Category{
...
public function description(){
return $this->hasOne(CategoryDesc::class);
}
...
}
$category = Category::create([
'image' => $image,
'parent_id' => $request->input('parent_id'),
'status' => $request->input('status'),
'sort_order' => isset($sort_order) ? $sort_order : '0'
]);
$category->description()->create([
'language_id' => $language->language_id,
'name' => $request->input($name),
'meta_title' => $request->input($meta_title),
'meta_description' => $request->input($meta_description)
]);
public function toArray($request)
{
return [
'id' => $this->id,
'title' => $this->title,
'slug' => $this->slug,
'author' => new AuthorResource($this->mod_author),
'sticky' => $this->sticky,
'categories' => CategoryResource::collection($this->categories),
'files' => [
'archives' => FileResource::collection($this->files->where('type', '=', 'archive')),
'images' => FileResource::collection($this->files->where('type', '=', 'images')),
'thumbnail' => FileResource::collection($this->files->where('type', '=', 'thumbnail'))
]
];
}
public function index()
{
$mods = Mod::with('categories')
->with('mod_author')
->with(['files' => function($query){
return $query->where('type', 'mod');
}])
->paginate('10');
return ModResource::collection($mods);
}
public function toArray($request)
{
return [
'id' => $this->id,
'title' => $this->title,
'slug' => $this->slug,
'author' => new AuthorResource($this->mod_author),
'sticky' => $this->sticky,
'categories' => CategoryResource::collection($this->categories),
'files' => $this->whenLoaded('files', [
'archives' => $this->files,
])
];
}
public function delete(User $user, Menu $menu) {
// dd($menu->project->id, $menu->project_id);
return $this->projectPolicy->isAdmin($user, $menu->project);
}
public function delete(User $user, Menu $menu) {
return $user->can('delete-menu', $menu->project);
}
public function items(): BelongsToMany
{
return $this->belongsToMany(CartProduct::class, 'cart_products');
}
public function items(): BelongsToMany
{
return $this->belongsToMany(ProductVariant::class, 'cart_products');
}