/
home
/
henzagold
/
server
/
app
/
Http
/
Controllers
/
Customer
/
File Upload :
llllll
Current File: /home/henzagold/server/app/Http/Controllers/Customer/FavController.php
<?php namespace App\Http\Controllers\Customer; use App\Http\Controllers\Controller; use App\Models\Fav; use App\Models\Product; use Illuminate\Http\Request; class FavController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $favs = Fav::where('customer_id' , auth()->id())->with('product')->get(); return response()->json($favs); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $this->validate($request,[ 'product_id'=>'required' ]); $input = $request->all(); $input['customer_id'] = auth()->id(); Fav::firstOrCreate($input); Product::findOrFail($input['product_id'])->increment('count_fav'); return response()->json(true); } /** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { // } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { // } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { // } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $input = ['product_id'=>$id]; $input['customer_id'] = auth()->id(); Fav::where('customer_id' , $input['customer_id'])->where('product_id' , $input['product_id'])->delete(); Product::findOrFail($id)->decrement('count_fav'); return response()->json(true); } }
Copyright ©2k19 -
Hexid
|
Tex7ure