46 lines
849 B
PHP
46 lines
849 B
PHP
<?php
|
|
|
|
namespace App\Repositories\Shop;
|
|
|
|
use App\Models\Shop\Basket;
|
|
use App\Traits\Model\Basic;
|
|
use Darryldecode\Cart\CartCollection;
|
|
|
|
class BasketStores
|
|
{
|
|
use Basic;
|
|
|
|
public function has($key)
|
|
{
|
|
return Basket::find($key);
|
|
}
|
|
|
|
public function get($key)
|
|
{
|
|
if ($this->has($key)) {
|
|
return new CartCollection(Basket::find($key)->cart_data);
|
|
} else {
|
|
return [];
|
|
}
|
|
}
|
|
|
|
public function put($key, $value)
|
|
{
|
|
if ($row = Basket::find($key)) {
|
|
// update
|
|
$row->cart_data = $value;
|
|
$row->save();
|
|
} else {
|
|
Basket::create([
|
|
'id' => $key,
|
|
'cart_data' => $value,
|
|
]);
|
|
}
|
|
}
|
|
|
|
public static function getModel()
|
|
{
|
|
return Basket::query();
|
|
}
|
|
}
|