|
|
|
@ -15,9 +15,10 @@ class UserFavController extends Controller |
|
|
|
{ |
|
|
|
public function index() |
|
|
|
{ |
|
|
|
$list = UserFav::query()->with([ |
|
|
|
'agentProduct' => fn($query) => $query->select('id', 'price', 'original_price'), |
|
|
|
'product' => fn($query) => $query->select('id', 'title', 'pictures'), |
|
|
|
$list = UserFav::query() |
|
|
|
->with([ |
|
|
|
'agentProduct:id,price,original_price', |
|
|
|
'product:id,title,pictures', |
|
|
|
]) |
|
|
|
->where('user_id', $this->user_id) |
|
|
|
->select('id', 'agent_product_id', 'product_id', 'created_at') |
|
|
|
@ -30,7 +31,7 @@ class UserFavController extends Controller |
|
|
|
{ |
|
|
|
$id = (int)request()->input('id'); |
|
|
|
|
|
|
|
$agent_product = AgentProduct::where('user_id', $this->user_id)->find($id); |
|
|
|
$agent_product = AgentProduct::find($id); |
|
|
|
if (!$agent_product) { |
|
|
|
return $this->error('产品不存在或已被删除'); |
|
|
|
} |
|
|
|
@ -44,4 +45,12 @@ class UserFavController extends Controller |
|
|
|
|
|
|
|
return $this->success(); |
|
|
|
} |
|
|
|
|
|
|
|
public function delete() |
|
|
|
{ |
|
|
|
$id = (int)request()->input('id'); |
|
|
|
|
|
|
|
UserFav::where('user_id', $this->user_id)->find($id)->delete(); |
|
|
|
return $this->success(); |
|
|
|
} |
|
|
|
} |