first commit
This commit is contained in:
0
Modules/Supplier/app/Http/Controllers/.gitkeep
Normal file
0
Modules/Supplier/app/Http/Controllers/.gitkeep
Normal file
138
Modules/Supplier/app/Http/Controllers/SupplierController.php
Normal file
138
Modules/Supplier/app/Http/Controllers/SupplierController.php
Normal file
@ -0,0 +1,138 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Supplier\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Admin\Repositories\FieldInterface;
|
||||
use Modules\Admin\Services\AdminService;
|
||||
use Modules\Supplier\Repositories\SupplierInterface;
|
||||
use Modules\User\Repositories\UserInterface;
|
||||
|
||||
class SupplierController extends Controller
|
||||
{
|
||||
private $userRepository;
|
||||
private $supplierRepository;
|
||||
private $adminService;
|
||||
private $fieldRepository;
|
||||
|
||||
public function __construct(
|
||||
FieldInterface $fieldRepository,
|
||||
UserInterface $userRepository,
|
||||
AdminService $adminService,
|
||||
SupplierInterface $supplierRepository) {
|
||||
$this->userRepository = $userRepository;
|
||||
$this->adminService = $adminService;
|
||||
$this->fieldRepository = $fieldRepository;
|
||||
$this->supplierRepository = $supplierRepository;
|
||||
}
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$data['title'] = 'Supplier List';
|
||||
$data['suppliers'] = $this->supplierRepository->findAll();
|
||||
|
||||
return view('supplier::supplier.index', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$data['title'] = 'Create Supplier';
|
||||
$data['nationalityList'] = $this->fieldRepository->getDropdownByAlias('nationality');
|
||||
return view('supplier::supplier.create', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
$inputData = $request->all();
|
||||
try {
|
||||
|
||||
if ($request->hasFile('profile_picture')) {
|
||||
$inputData['profile_picture'] = uploadImage($request->profile_picture);
|
||||
}
|
||||
$this->supplierRepository->create($inputData);
|
||||
|
||||
sendNotification(auth()->user(), [
|
||||
'msg' => 'Supplier Created',
|
||||
]);
|
||||
|
||||
toastr()->success('supplier Created Succesfully');
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
echo $th->getMessage();
|
||||
toastr()->error($th->getMessage());
|
||||
}
|
||||
return redirect()->route('supplier.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$data['title'] = 'Show Suppliers';
|
||||
$data['supplier'] = $this->supplierRepository->getSupplierById($id);
|
||||
return view('supplier::supplier.show', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$data['title'] = 'Edit Supplier';
|
||||
$data['supplier'] = $this->supplierRepository->getSupplierById($id);
|
||||
$data['nationalityList'] = $this->fieldRepository->getDropdownByAlias('nationality');
|
||||
return view('supplier::supplier.edit', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, $id): RedirectResponse
|
||||
{
|
||||
$inputData = $request->except(['_method', '_token']);
|
||||
try {
|
||||
if ($request->hasFile('profile_picture')) {
|
||||
$inputData['profile_picture'] = uploadImage($request->profile_picture);
|
||||
}
|
||||
$this->supplierRepository->update($id, $inputData);
|
||||
|
||||
sendNotification(auth()->user(), [
|
||||
'msg' => 'supplier Updated',
|
||||
]);
|
||||
|
||||
toastr()->success('supplier Updated Succesfully');
|
||||
} catch (\Throwable $th) {
|
||||
toastr()->error($th->getMessage());
|
||||
}
|
||||
return redirect()->route('supplier.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
try {
|
||||
$CustomerModel = $this->supplierRepository->getSupplierById($id);
|
||||
$CustomerModel->delete();
|
||||
|
||||
toastr()->success('Supplier Delete Succesfully');
|
||||
} catch (\Throwable $th) {
|
||||
toastr()->error($th->getMessage());
|
||||
}
|
||||
|
||||
return response()->json(['status' => true, 'message' => 'supplier Delete Succesfully']);
|
||||
|
||||
}
|
||||
}
|
0
Modules/Supplier/app/Http/Requests/.gitkeep
Normal file
0
Modules/Supplier/app/Http/Requests/.gitkeep
Normal file
Reference in New Issue
Block a user