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
0
Modules/Supplier/app/Models/.gitkeep
Normal file
0
Modules/Supplier/app/Models/.gitkeep
Normal file
11
Modules/Supplier/app/Models/Supplier.php
Normal file
11
Modules/Supplier/app/Models/Supplier.php
Normal file
@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Supplier\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Supplier extends Model
|
||||
{
|
||||
protected $table = 'tbl_suppliers';
|
||||
protected $guarded = [];
|
||||
}
|
0
Modules/Supplier/app/Observers/.gitkeep
Normal file
0
Modules/Supplier/app/Observers/.gitkeep
Normal file
0
Modules/Supplier/app/Providers/.gitkeep
Normal file
0
Modules/Supplier/app/Providers/.gitkeep
Normal file
49
Modules/Supplier/app/Providers/RouteServiceProvider.php
Normal file
49
Modules/Supplier/app/Providers/RouteServiceProvider.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Supplier\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Called before routes are registered.
|
||||
*
|
||||
* Register any model bindings or pattern based filters.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
parent::boot();
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the routes for the application.
|
||||
*/
|
||||
public function map(): void
|
||||
{
|
||||
$this->mapApiRoutes();
|
||||
|
||||
$this->mapWebRoutes();
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the "web" routes for the application.
|
||||
*
|
||||
* These routes all receive session state, CSRF protection, etc.
|
||||
*/
|
||||
protected function mapWebRoutes(): void
|
||||
{
|
||||
Route::middleware('web')->group(module_path('Supplier', '/routes/web.php'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the "api" routes for the application.
|
||||
*
|
||||
* These routes are typically stateless.
|
||||
*/
|
||||
protected function mapApiRoutes(): void
|
||||
{
|
||||
Route::middleware('api')->prefix('api')->name('api.')->group(module_path('Supplier', '/routes/api.php'));
|
||||
}
|
||||
}
|
117
Modules/Supplier/app/Providers/SupplierServiceProvider.php
Normal file
117
Modules/Supplier/app/Providers/SupplierServiceProvider.php
Normal file
@ -0,0 +1,117 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Supplier\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
use Modules\Supplier\Repositories\SupplierInterface;
|
||||
use Modules\Supplier\Repositories\SupplierRepository;
|
||||
|
||||
class SupplierServiceProvider extends ServiceProvider
|
||||
{
|
||||
protected string $moduleName = 'Supplier';
|
||||
|
||||
protected string $moduleNameLower = 'supplier';
|
||||
|
||||
/**
|
||||
* Boot the application events.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
$this->registerCommands();
|
||||
$this->registerCommandSchedules();
|
||||
$this->registerTranslations();
|
||||
$this->registerConfig();
|
||||
$this->registerViews();
|
||||
$this->loadMigrationsFrom(module_path($this->moduleName, 'database/migrations'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Register the service provider.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->bind(SupplierInterface::class, SupplierRepository::class);
|
||||
$this->app->register(RouteServiceProvider::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register commands in the format of Command::class
|
||||
*/
|
||||
protected function registerCommands(): void
|
||||
{
|
||||
// $this->commands([]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register command Schedules.
|
||||
*/
|
||||
protected function registerCommandSchedules(): void
|
||||
{
|
||||
// $this->app->booted(function () {
|
||||
// $schedule = $this->app->make(Schedule::class);
|
||||
// $schedule->command('inspire')->hourly();
|
||||
// });
|
||||
}
|
||||
|
||||
/**
|
||||
* Register translations.
|
||||
*/
|
||||
public function registerTranslations(): void
|
||||
{
|
||||
$langPath = resource_path('lang/modules/' . $this->moduleNameLower);
|
||||
|
||||
if (is_dir($langPath)) {
|
||||
$this->loadTranslationsFrom($langPath, $this->moduleNameLower);
|
||||
$this->loadJsonTranslationsFrom($langPath);
|
||||
} else {
|
||||
$this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower);
|
||||
$this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Register config.
|
||||
*/
|
||||
protected function registerConfig(): void
|
||||
{
|
||||
$this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower . '.php')], 'config');
|
||||
$this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower);
|
||||
}
|
||||
|
||||
/**
|
||||
* Register views.
|
||||
*/
|
||||
public function registerViews(): void
|
||||
{
|
||||
$viewPath = resource_path('views/modules/' . $this->moduleNameLower);
|
||||
$sourcePath = module_path($this->moduleName, 'resources/views');
|
||||
|
||||
$this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower . '-module-views']);
|
||||
|
||||
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower);
|
||||
|
||||
$componentNamespace = str_replace('/', '\\', config('modules.namespace') . '\\' . $this->moduleName . '\\' . ltrim(config('modules.paths.generator.component-class.path'), config('modules.paths.app_folder', '')));
|
||||
Blade::componentNamespace($componentNamespace, $this->moduleNameLower);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the services provided by the provider.
|
||||
*/
|
||||
public function provides(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
private function getPublishableViewPaths(): array
|
||||
{
|
||||
$paths = [];
|
||||
foreach (config('view.paths') as $path) {
|
||||
if (is_dir($path . '/modules/' . $this->moduleNameLower)) {
|
||||
$paths[] = $path . '/modules/' . $this->moduleNameLower;
|
||||
}
|
||||
}
|
||||
|
||||
return $paths;
|
||||
}
|
||||
}
|
0
Modules/Supplier/app/Repositories/.gitkeep
Normal file
0
Modules/Supplier/app/Repositories/.gitkeep
Normal file
15
Modules/Supplier/app/Repositories/SupplierInterface.php
Normal file
15
Modules/Supplier/app/Repositories/SupplierInterface.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Supplier\Repositories;
|
||||
|
||||
interface SupplierInterface
|
||||
{
|
||||
public function findAll();
|
||||
public function getSupplierById($SupplierId);
|
||||
public function getSupplierByEmail($email);
|
||||
public function delete($SupplierId);
|
||||
public function create($SupplierDetails);
|
||||
public function update($SupplierId, array $newDetails);
|
||||
public function pluck();
|
||||
|
||||
}
|
49
Modules/Supplier/app/Repositories/SupplierRepository.php
Normal file
49
Modules/Supplier/app/Repositories/SupplierRepository.php
Normal file
@ -0,0 +1,49 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Supplier\Repositories;
|
||||
|
||||
use Modules\Supplier\Models\Supplier;
|
||||
|
||||
class SupplierRepository implements SupplierInterface
|
||||
{
|
||||
public function findAll()
|
||||
{
|
||||
return Supplier::when(true, function ($query) {
|
||||
// if (auth()->user()->hasRole('Supplier')) {
|
||||
// $user = \Auth::user();
|
||||
// $query->where('id', $user->Supplier_id);
|
||||
// }
|
||||
})->paginate(20);
|
||||
}
|
||||
|
||||
public function getSupplierById($SupplierId)
|
||||
{
|
||||
return Supplier::findOrFail($SupplierId);
|
||||
}
|
||||
|
||||
public function getSupplierByEmail($email)
|
||||
{
|
||||
return Supplier::where('email', $email)->first();
|
||||
}
|
||||
|
||||
public function delete($SupplierId)
|
||||
{
|
||||
Supplier::destroy($SupplierId);
|
||||
}
|
||||
|
||||
public function create($SupplierDetails)
|
||||
{
|
||||
return Supplier::create($SupplierDetails);
|
||||
}
|
||||
|
||||
public function update($SupplierId, array $newDetails)
|
||||
{
|
||||
return Supplier::whereId($SupplierId)->update($newDetails);
|
||||
}
|
||||
|
||||
public function pluck()
|
||||
{
|
||||
return Supplier::pluck('supplier_name', 'id');
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user