Edit File: AdditiveController.php
<?php namespace App\Http\Controllers\StoresDashboard; use App\Http\Controllers\Controller; use Illuminate\Http\Request; use App\Http\Requests\StoreAdditiveCategoryRequest; use App\Models\Store; use App\Models\ProductAdditiveCategory; use Auth; use Redirect; class AdditiveController extends Controller { // public function get_additives(Request $request) { $user = Auth::user(); $store = Store::where('user_id', $user->id) ->first(); $additives = ProductAdditiveCategory::where('store_id', $store->id)->get(); return view('stores_dashboard.additives.additives', compact('store', 'additives', 'user')); } public function get_add_additive(Request $request) { $user = Auth::user(); $store = Store::where('user_id', $user->id) ->first(); return view('stores_dashboard.additives.add_additive', compact('store', 'user')); } public function post_additive(StoreAdditiveCategoryRequest $request) { $data = $request->validated(); $additive = new ProductAdditiveCategory(); $additive->name = [ 'ar' => $data['name_ar'], 'en' => $data['name_en'] ]; $additive->store_id = $data['store_id']; $additive->save(); $store = Store::find($data['store_id']); $store->updateCacheWithProducts(); $msg = trans('dashboard.created_successfully'); $url = route('stores_dashboard.get_additives'); return response()->json([ 'key' => 'success', 'msg' => $msg, 'url' => $url ]); } public function get_edit_additive(Request $request, $id) { $user = Auth::user(); $store = Store::where('user_id', $user->id) ->first(); $additive = ProductAdditiveCategory::find($id); return view('stores_dashboard.additives.edit_additive', compact('store', 'user', 'additive')); } public function post_edit_additive(StoreAdditiveCategoryRequest $request) { $data = $request->validated(); $additive = ProductAdditiveCategory::find($request['additive_id']); $additive->name = [ 'ar' => $data['name_ar'], 'en' => $data['name_en'] ]; $additive->store_id = $data['store_id']; $additive->update(); $store = Store::find($data['store_id']); $store->updateCacheWithProducts(); $msg = trans('dashboard.alerts.updated_successfully'); $url = route('stores_dashboard.get_additives'); return response()->json([ 'key' => 'success', 'msg' => $msg, 'url' => $url ]); } public function delete_additive(Request $request) { $additive = ProductAdditiveCategory::find($request['id']); $additive->delete(); $msg = trans('auth.deleted_success'); $store = Store::find($additive->store_id); $store->updateCacheWithProducts(); $url = route('stores_dashboard.get_additives'); return response()->json([ 'key' => 'success', 'msg' => $msg, 'url' => $url ]); } }
Back to File Manager