first commit

This commit is contained in:
Sampanna Rimal
2024-08-27 17:48:06 +05:45
commit 53c0140f58
10839 changed files with 1125847 additions and 0 deletions

View File

@@ -0,0 +1,146 @@
<?php
namespace Modules\Customer\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\Customer\Repositories\CustomerInterface;
use Modules\User\Repositories\UserInterface;
class CustomerController extends Controller
{
private $userRepository;
private $customerRepository;
private $adminService;
private $fieldRepository;
public function __construct(
FieldInterface $fieldRepository,
UserInterface $userRepository,
AdminService $adminService,
CustomerInterface $customerRepository) {
$this->userRepository = $userRepository;
$this->adminService = $adminService;
$this->fieldRepository = $fieldRepository;
$this->customerRepository = $customerRepository;
}
/**
* Display a listing of the resource.
*/
public function index()
{
$data['title'] = 'Customer List';
$data['customers'] = $this->customerRepository->findAll();
return view('customer::customer.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = 'Create Customer';
$data['nationalityList'] = $this->fieldRepository->getDropdownByAlias('nationality');
return view('customer::customer.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
$inputData = $request->all();
$this->customerRepository->create($inputData);
toastr()->success('Customer Created Succesfully');
try {
if ($request->hasFile('profile_picture')) {
$inputData['profile_picture'] = uploadImage($request->profile_picture);
}
sendNotification(auth()->user(), [
'msg' => 'Customer Created',
]);
} catch (\Throwable $th) {
echo $th->getMessage();
toastr()->error($th->getMessage());
}
return redirect()->route('customer.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
$data['title'] = 'Show Customer';
$data['customer'] = $this->customerRepository->getCustomerById($id);
return view('customer::customer.show', $data);
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$data['title'] = 'Edit Customer';
$data['customer'] = $this->customerRepository->getCustomerById($id);
$data['departmentList'] = $this->adminService->pluckDepartments();
$data['designationList'] = $this->adminService->pluckDesignations();
$data['nationalityList'] = $this->fieldRepository->getDropdownByAlias('nationality');
$data['genderList'] = $this->fieldRepository->getDropdownByAlias('gender');
$data['casteList'] = $this->fieldRepository->getDropdownByAlias('caste');
$data['cityList'] = $this->adminService->pluckCities();
return view('customer::customer.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->customerRepository->update($id, $inputData);
sendNotification(auth()->user(), [
'msg' => 'Customer Updated',
]);
toastr()->success('Customer Updated Succesfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('customer.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
$CustomerModel = $this->customerRepository->getCustomerById($id);
$CustomerModel->delete();
toastr()->success('Customer Delete Succesfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return response()->json(['status' => true, 'message' => 'Customer Delete Succesfully']);
}
}

View File

View File

@@ -0,0 +1,13 @@
<?php
namespace Modules\Customer\Models;
use Illuminate\Database\Eloquent\Model;
class Customer extends Model
{
protected $table = 'tbl_customers';
protected $guarded = [];
}

View File

View File

View File

@@ -0,0 +1,117 @@
<?php
namespace Modules\Customer\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Modules\Customer\Repositories\CustomerInterface;
use Modules\Customer\Repositories\CustomerRepository;
class CustomerServiceProvider extends ServiceProvider
{
protected string $moduleName = 'Customer';
protected string $moduleNameLower = 'customer';
/**
* 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(CustomerInterface::class, CustomerRepository::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;
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace Modules\Customer\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('Customer', '/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('Customer', '/routes/api.php'));
}
}

View File

@@ -0,0 +1,15 @@
<?php
namespace Modules\Customer\Repositories;
interface CustomerInterface
{
public function findAll();
public function getCustomerById($CustomerId);
public function getCustomerByEmail($email);
public function delete($CustomerId);
public function create($CustomerDetails);
public function update($CustomerId, array $newDetails);
public function pluck();
}

View File

@@ -0,0 +1,49 @@
<?php
namespace Modules\Customer\Repositories;
use Modules\Customer\Models\Customer;
class CustomerRepository implements CustomerInterface
{
public function findAll()
{
return Customer::when(true, function ($query) {
// if (auth()->user()->hasRole('Customer')) {
// $user = \Auth::user();
// $query->where('id', $user->Customer_id);
// }
})->paginate(20);
}
public function getCustomerById($CustomerId)
{
return Customer::findOrFail($CustomerId);
}
public function getCustomerByEmail($email)
{
return Customer::where('email', $email)->first();
}
public function delete($CustomerId)
{
Customer::destroy($CustomerId);
}
public function create($CustomerDetails)
{
return Customer::create($CustomerDetails);
}
public function update($CustomerId, array $newDetails)
{
return Customer::whereId($CustomerId)->update($newDetails);
}
public function pluck()
{
return Customer::pluck('customer_name', 'id');
}
}