changes
This commit is contained in:
@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Product\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Product\Models\FabricCategory;
|
||||
use Modules\Product\Repositories\FabricCategoryRepository;
|
||||
|
||||
class FabricCategoryController extends Controller
|
||||
{
|
||||
private $fabricCategoryRepository;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function __construct(
|
||||
FabricCategoryRepository $fabricCategoryRepository)
|
||||
{
|
||||
$this->fabricCategoryRepository = $fabricCategoryRepository;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$data['title'] = 'Fabric Categories List';
|
||||
$data['fabric_categories'] = $this->fabricCategoryRepository->findAll();
|
||||
|
||||
return view('product::fabric_category.index', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$data['title'] = 'Create Fabric Categories';
|
||||
$data['status'] = FabricCategory::STATUS;
|
||||
|
||||
return view('product::fabric_category.create', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
|
||||
$request->request->add(['slug' => slugify($request->title)]);
|
||||
$inputData = $request->all();
|
||||
$this->fabricCategoryRepository->create($inputData);
|
||||
toastr()->success('Category Created Succesfully');
|
||||
|
||||
return redirect()->route('fabricCategory.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$data['title'] = 'Show Fabric Category';
|
||||
$data['status'] = FabricCategory::STATUS;
|
||||
$data['fabric_category'] = $this->fabricCategoryRepository->getFabricCategoryById($id);
|
||||
|
||||
return view('product::fabric_category.show', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$data['title'] = 'Edit Fabric Category';
|
||||
$data['status'] = FabricCategory::STATUS;
|
||||
$data['fabric_category'] = $this->fabricCategoryRepository->getFabricCategoryById($id);
|
||||
|
||||
return view('product::fabric_category.edit', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, $id): RedirectResponse
|
||||
{
|
||||
$inputData = $request->except(['_method', '_token']);
|
||||
$this->fabricCategoryRepository->update($id, $inputData);
|
||||
|
||||
return redirect()->route('fabricCategory.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
try {
|
||||
$FabricCategoryModel = $this->fabricCategoryRepository->getFabricCategoryById($id);
|
||||
$FabricCategoryModel->delete();
|
||||
|
||||
toastr()->success('Fabric Category Delete Succesfully');
|
||||
} catch (\Throwable $th) {
|
||||
toastr()->error($th->getMessage());
|
||||
}
|
||||
|
||||
return response()->json(['status' => true, 'message' => 'Fabric Category Delete Succesfully']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -5,8 +5,10 @@ namespace Modules\Product\Http\Controllers;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Product\Models\FabricCategory;
|
||||
use Modules\Product\Models\Product;
|
||||
use Modules\Product\Repositories\CategoryRepository;
|
||||
use Modules\Product\Repositories\FabricCategoryRepository;
|
||||
use Modules\Product\Repositories\ProductInterface;
|
||||
use Modules\Product\Repositories\ProductRepository;
|
||||
use Modules\Product\Repositories\SubCategoryRepository;
|
||||
@ -19,6 +21,7 @@ class ProductController extends Controller
|
||||
private $productRepository;
|
||||
private $categoryRepository;
|
||||
private $subCategoryRepository;
|
||||
private $fabricCategoryRepository;
|
||||
private $warehouseRepository;
|
||||
private $supplierRepository;
|
||||
|
||||
@ -29,11 +32,13 @@ class ProductController extends Controller
|
||||
CategoryRepository $categoryRepository,
|
||||
SubCategoryRepository $subCategoryRepository,
|
||||
SupplierRepository $supplierRepository,
|
||||
FabricCategoryRepository $fabricCategoryRepository,
|
||||
WarehouseRepository $warehouseRepository)
|
||||
{
|
||||
$this->productRepository = $productRepository;
|
||||
$this->categoryRepository = $categoryRepository;
|
||||
$this->subCategoryRepository = $subCategoryRepository;
|
||||
$this->fabricCategoryRepository = $fabricCategoryRepository;
|
||||
$this->supplierRepository = $supplierRepository;
|
||||
$this->warehouseRepository = $warehouseRepository;
|
||||
}
|
||||
@ -52,6 +57,7 @@ class ProductController extends Controller
|
||||
{
|
||||
$data['title'] = 'Create Product';
|
||||
$data['category'] = $this->categoryRepository->pluck();
|
||||
$data['fabricCategory'] = $this->fabricCategoryRepository->pluck();
|
||||
$data['subCategory'] = $this->subCategoryRepository->pluck();
|
||||
$data['supplier'] = $this->supplierRepository->pluck();
|
||||
$data['warehouse'] = $this->warehouseRepository->pluck();
|
||||
@ -92,6 +98,7 @@ class ProductController extends Controller
|
||||
$data['title'] = 'Show Product';
|
||||
$data['category'] = $this->categoryRepository->pluck();
|
||||
$data['subCategory'] = $this->subCategoryRepository->pluck();
|
||||
$data['fabricCategory'] = $this->fabricCategoryRepository->pluck();
|
||||
$data['supplier'] = $this->supplierRepository->pluck();
|
||||
$data['warehouse'] = $this->warehouseRepository->pluck();
|
||||
$data['product'] = $this->productRepository->getProductById($id);
|
||||
@ -127,4 +134,18 @@ class ProductController extends Controller
|
||||
|
||||
return response()->json(['status' => true, 'message' => 'Product Delete Succesfully']);
|
||||
}
|
||||
|
||||
public function getProductDetail(Request $request)
|
||||
{
|
||||
try {
|
||||
$productModel = $this->productRepository->getProductById($request->id);
|
||||
} catch (\Throwable $th) {
|
||||
toastr()->error($th->getMessage());
|
||||
|
||||
}
|
||||
return response()->json([
|
||||
'status' => true,
|
||||
'data' => $productModel,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
16
Modules/Product/app/Models/FabricCategory.php
Normal file
16
Modules/Product/app/Models/FabricCategory.php
Normal file
@ -0,0 +1,16 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Product\Models;
|
||||
|
||||
use App\Traits\StatusTrait;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class FabricCategory extends Model
|
||||
{
|
||||
USE StatusTrait;
|
||||
|
||||
protected $table = 'tbl_fabriccategories';
|
||||
protected $guarded = [];
|
||||
protected $appends = ['status_name'];
|
||||
|
||||
}
|
@ -6,6 +6,7 @@ use App\Traits\StatusTrait;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Modules\Supplier\Models\Supplier;
|
||||
|
||||
|
||||
class Product extends Model
|
||||
{
|
||||
USE StatusTrait;
|
||||
@ -25,10 +26,16 @@ class Product extends Model
|
||||
return $this->belongsTo(SubCategory::class, 'sub_category_id');
|
||||
}
|
||||
|
||||
public function fabricCategory()
|
||||
{
|
||||
return $this->belongsTo(FabricCategory::class, 'fabriccategory_id');
|
||||
}
|
||||
|
||||
public function warehouse()
|
||||
{
|
||||
return $this->belongsTo(Warehouse::class, 'warehouse_id');
|
||||
}
|
||||
|
||||
public function supplier()
|
||||
{
|
||||
return $this->belongsTo(Supplier::class, 'supplier_id');
|
||||
|
@ -4,6 +4,10 @@ namespace Modules\Product\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Modules\Product\Repositories\CategoryInterface;
|
||||
use Modules\Product\Repositories\CategoryRepository;
|
||||
use Modules\Product\Repositories\FabricCategoryInterface;
|
||||
use Modules\Product\Repositories\FabricCategoryRepository;
|
||||
use Modules\Product\Repositories\ProductInterface;
|
||||
use Modules\Product\Repositories\ProductRepository;
|
||||
|
||||
@ -33,6 +37,9 @@ class ProductServiceProvider extends ServiceProvider
|
||||
{
|
||||
$this->app->bind(ProductInterface::class,ProductRepository::class);
|
||||
$this->app->register(RouteServiceProvider::class);
|
||||
$this->app->bind(CategoryInterface::class,CategoryRepository::class);
|
||||
$this->app->bind(FabricCategoryInterface::class,FabricCategoryRepository::class);
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
15
Modules/Product/app/Repositories/FabricCategoryInterface.php
Normal file
15
Modules/Product/app/Repositories/FabricCategoryInterface.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Product\Repositories;
|
||||
|
||||
interface FabricCategoryInterface
|
||||
{
|
||||
public function findAll();
|
||||
public function getFabricCategoryById($FabricCategoryId);
|
||||
public function getFabricCategoryByEmail($email);
|
||||
public function delete($FabricCategoryId);
|
||||
public function create($FabricCategoryDetails);
|
||||
public function update($FabricCategoryId, array $newDetails);
|
||||
public function pluck();
|
||||
|
||||
}
|
@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Product\Repositories;
|
||||
|
||||
use Modules\Product\Models\FabricCategory;
|
||||
|
||||
class FabricCategoryRepository implements FabricCategoryInterface
|
||||
{
|
||||
public function findAll()
|
||||
{
|
||||
return FabricCategory::when(true, function ($query) {
|
||||
|
||||
})->paginate(20);
|
||||
}
|
||||
|
||||
public function getFabricCategoryById($FabricCategoryId)
|
||||
{
|
||||
return FabricCategory::findOrFail($FabricCategoryId);
|
||||
}
|
||||
|
||||
public function getFabricCategoryByEmail($email)
|
||||
{
|
||||
return FabricCategory::where('email', $email)->first();
|
||||
}
|
||||
|
||||
public function delete($FabricCategoryId)
|
||||
{
|
||||
FabricCategory::destroy($FabricCategoryId);
|
||||
}
|
||||
|
||||
public function create($FabricCategoryDetails)
|
||||
{
|
||||
return FabricCategory::create($FabricCategoryDetails);
|
||||
}
|
||||
|
||||
public function update($FabricCategoryId, array $newDetails)
|
||||
{
|
||||
return FabricCategory::whereId($FabricCategoryId)->update($newDetails);
|
||||
}
|
||||
|
||||
public function pluck()
|
||||
{
|
||||
return FabricCategory::pluck('title', 'id');
|
||||
}
|
||||
|
||||
}
|
@ -44,3 +44,4 @@ class ProductRepository implements ProductInterface
|
||||
}
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user