/home/techb158/dev.balacoffee.com/app/Http/Controllers
NameSizeModeActions
Auth/-0755rm
hrm/-0755rm
AdjustmentController.php319350644editdlrm
AuthController.php17610644editdlrm
BaseController.php31830644editdlrm
BrandsController.php58040644editdlrm
CategorieController.php36250644editdlrm
CategoryExpenseController.php54490644editdlrm
ClientController.php84670644editdlrm
Controller.php3740644editdlrm
CurrencyController.php40350644editdlrm
ExpensesController.php126700644editdlrm
HomeController.php4950644editdlrm
PasswordResetController.php38950644editdlrm
PaymentPurchaseReturnsController.php146500644editdlrm
PaymentPurchasesController.php141380644editdlrm
PaymentSaleReturnsController.php143030644editdlrm
PaymentSalesController.php217990644editdlrm
PermissionsController.php65310644editdlrm
PosController.php166510644editdlrm
ProductsController.php485200644editdlrm
ProvidersController.php72790644editdlrm
PurchasesController.php472790644editdlrm
PurchasesReturnController.php483660644editdlrm
QuotationsController.php314620644editdlrm
ReportController.php1493230644editdlrm
SalesController.php644200644editdlrm
SalesReturnController.php470940644editdlrm
SettingsController.php123540644editdlrm
SetupController.php87700644editdlrm
ShipmentController.php76330644editdlrm
TestDbController.php31560644editdlrm
TransferController.php545740644editdlrm
UnitsController.php61620644editdlrm
UpdateController.php20640644editdlrm
UserController.php131670644editdlrm
WarehouseController.php64270644editdlrm
Edit: /home/techb158/dev.balacoffee.com/app/Http/Controllers/BrandsController.php (5804B)
authorizeForUser($request->user('api'), 'view', Brand::class); // How many items do you want to display. $perPage = $request->limit; $pageStart = \Request::get('page', 1); // Start displaying items from this number; $offSet = ($pageStart * $perPage) - $perPage; $order = $request->SortField; $dir = $request->SortType; $helpers = new helpers(); $brands = Brand::where('deleted_at', '=', null) // Search With Multiple Param ->where(function ($query) use ($request) { return $query->when($request->filled('search'), function ($query) use ($request) { return $query->where('name', 'LIKE', "%{$request->search}%") ->orWhere('description', 'LIKE', "%{$request->search}%"); }); }); $totalRows = $brands->count(); if($perPage == "-1"){ $perPage = $totalRows; } $brands = $brands->offset($offSet) ->limit($perPage) ->orderBy($order, $dir) ->get(); return response()->json([ 'brands' => $brands, 'totalRows' => $totalRows, ]); } //---------------- STORE NEW Brand -------------\\ public function store(Request $request) { $this->authorizeForUser($request->user('api'), 'create', Brand::class); request()->validate([ 'name' => 'required', ]); \DB::transaction(function () use ($request) { if ($request->hasFile('image')) { $image = $request->file('image'); $filename = rand(11111111, 99999999) . $image->getClientOriginalName(); $image_resize = Image::make($image->getRealPath()); $image_resize->resize(200, 200); $image_resize->save(public_path('/images/brands/' . $filename)); } else { $filename = 'no-image.png'; } $Brand = new Brand; $Brand->name = $request['name']; $Brand->description = $request['description']; $Brand->image = $filename; $Brand->save(); }, 10); return response()->json(['success' => true]); } //------------ function show -----------\\ public function show($id){ // } //---------------- UPDATE Brand -------------\\ public function update(Request $request, $id) { $this->authorizeForUser($request->user('api'), 'update', Brand::class); request()->validate([ 'name' => 'required', ]); \DB::transaction(function () use ($request, $id) { $Brand = Brand::findOrFail($id); $currentImage = $Brand->image; if ($currentImage && $request->image != $currentImage) { $image = $request->file('image'); $path = public_path() . '/images/brands'; $filename = rand(11111111, 99999999) . $image->getClientOriginalName(); $image_resize = Image::make($image->getRealPath()); $image_resize->resize(200, 200); $image_resize->save(public_path('/images/brands/' . $filename)); $BrandImage = $path . '/' . $currentImage; if (file_exists($BrandImage)) { if ($currentImage != 'no-image.png') { @unlink($BrandImage); } } } else if (!$currentImage && $request->image !='null'){ $image = $request->file('image'); $path = public_path() . '/images/brands'; $filename = rand(11111111, 99999999) . $image->getClientOriginalName(); $image_resize = Image::make($image->getRealPath()); $image_resize->resize(200, 200); $image_resize->save(public_path('/images/brands/' . $filename)); } else { $filename = $currentImage?$currentImage:'no-image.png'; } Brand::whereId($id)->update([ 'name' => $request['name'], 'description' => $request['description'], 'image' => $filename, ]); }, 10); return response()->json(['success' => true]); } //------------ Delete Brand -----------\\ public function destroy(Request $request, $id) { $this->authorizeForUser($request->user('api'), 'delete', Brand::class); Brand::whereId($id)->update([ 'deleted_at' => Carbon::now(), ]); return response()->json(['success' => true]); } //-------------- Delete by selection ---------------\\ public function delete_by_selection(Request $request) { $this->authorizeForUser($request->user('api'), 'delete', Brand::class); $selectedIds = $request->selectedIds; foreach ($selectedIds as $brand_id) { Brand::whereId($brand_id)->update([ 'deleted_at' => Carbon::now(), ]); } return response()->json(['success' => true]); } }