ok
Direktori : /home2/selectio/www/ecommerce-website/website/app/Http/Controllers/ |
Current File : /home2/selectio/www/ecommerce-website/website/app/Http/Controllers/payment_details.php |
<?php namespace App\Http\Controllers\Admin; use App\CPU\Helpers; use App\CPU\ImageManager; use App\Http\Controllers\Controller; use App\Model\Category; use App\Model\payment_details; use App\Model\Translation; use Illuminate\Http\Request; use Illuminate\Support\Str; use Brian2694\Toastr\Facades\Toastr; class payment_details extends Controller { public function index(Request $request) { $query_param = []; $search = $request['search']; if($request->has('search')) { $key = explode(' ', $request['search']); $categories = Category::where(function ($q) use ($key) { foreach ($key as $value) { $q->orWhere('name', 'like', "%{$value}%"); } }); $query_param = ['search' => $request['search']]; }else{ $categories = Category::where(['position' => 0]); } $categories = $categories->latest()->paginate(Helpers::pagination_limit())->appends($query_param); return view('admin-views.category.view', compact('categories','search')); } public function store_payment_details(Request $request) { $request->validate([ 'order_id' => 'required', 'myfile' => 'required', ], [ 'order_id.required' => 'name is required!', 'myfile.required' => 'Payment slip is required!', ]); $payment_detais = new payment_detais; $payment_detais->order_id = $request->order_id; $payment_detais->icon = ImageManager::upload('category/', 'png', $request->file('myfile')); $payment_detais->save(); $data = []; array_push($data, array( 'translationable_type' => 'App\Model\payment_detais', 'translationable_id' => $payment_detais->order_id, 'locale' => $key, 'key' => 'order_id', 'value' => $request->name[$index], )); Translation::insert($data); Toastr::success('Payment Details added successfully!'); return back(); } // public function Store_payment_details(Request $request) // { // error_log("file called"); // $request->validate([ // 'order_id' => 'required', // 'myfile' => 'required', // ], [ // 'order_id.required' => ' Order id is required!', // 'myfile.required' => '= Screen Shot Images is required!', // ]); // $payment_details = new Category; // $payment_details->order_id = $request->order_id; // $payment_details->icon = ImageManager::upload('category/', 'png', $request->file('myfile')); // $payment_details->save(); // Translation::insert($payment_details); // Toastr::success('Payement details added successfully!'); // return back(); // } public function edit(Request $request, $id) { $category = category::withoutGlobalScopes()->find($id); return view('admin-views.category.category-edit', compact('category')); } public function update(Request $request) { $category = Category::find($request->id); $category->name = $request->name[array_search('en', $request->lang)]; $category->slug = Str::slug($request->name[array_search('en', $request->lang)]); if ($request->image) { $category->icon = ImageManager::update('category/', $category->icon, 'png', $request->file('image')); } $category->priority = $request->priority; $category->save(); foreach ($request->lang as $index => $key) { if ($request->name[$index] && $key != 'en') { Translation::updateOrInsert( ['translationable_type' => 'App\Model\Category', 'translationable_id' => $category->id, 'locale' => $key, 'key' => 'name'], ['value' => $request->name[$index]] ); } } Toastr::success('Category updated successfully!'); return back(); } public function delete(Request $request) { $categories = Category::where('parent_id', $request->id)->get(); if (!empty($categories)) { foreach ($categories as $category) { $categories1 = Category::where('parent_id', $category->id)->get(); if (!empty($categories1)) { foreach ($categories1 as $category1) { $translation = Translation::where('translationable_type','App\Model\Category') ->where('translationable_id',$category1->id); $translation->delete(); Category::destroy($category1->id); } } $translation = Translation::where('translationable_type','App\Model\Category') ->where('translationable_id',$category->id); $translation->delete(); Category::destroy($category->id); } } $translation = Translation::where('translationable_type','App\Model\Category') ->where('translationable_id',$request->id); $translation->delete(); Category::destroy($request->id); return response()->json(); } public function fetch(Request $request) { if ($request->ajax()) { $data = Category::where('position', 0)->orderBy('id', 'desc')->get(); return response()->json($data); } } public function status(Request $request) { $category = Category::find($request->id); $category->home_status = $request->home_status; $category->save(); // Toastr::success('Service status updated!'); // return back(); return response()->json([ 'success' => 1, ], 200); } }