Method 1
Change the stock method as an activator of the Laravel model.
public function getStockAttribute(){
}
Get the results in the form of a collection and perform filtering in the "warehouse"; attribute
I would do something like.
Products::where('product','like','miraa')
->get()
->filter(function($item) {
return $item->stock > 100;
});
Learn more about filtering collections.
2
. scopes laravel.
public function scopeAvailbaleStock($query, $type)
{
return $query->where('type', $type);
}
$users = Products::available_stock()->get();
3
jarektkaczyk/eloquence
public function scopeWhereStock($query, $price, $operator = '=', $bool = 'and'){
$query->where('info1', $operator, $price, $bool);
}
Products::whereStock(25);
Products::whereStcok(25, '>');
Products::whereStock(25, '=', 'or');
Howerever, 1 2. , ,