firstcommit
This commit is contained in:
0
Modules/Customer/app/Http/Controllers/.gitkeep
Normal file
0
Modules/Customer/app/Http/Controllers/.gitkeep
Normal file
135
Modules/Customer/app/Http/Controllers/CustomerController.php
Normal file
135
Modules/Customer/app/Http/Controllers/CustomerController.php
Normal file
@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Customer\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Flasher\Prime\FlasherInterface;
|
||||
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 $fieldRepository;
|
||||
|
||||
public function __construct(
|
||||
FieldInterface $fieldRepository,
|
||||
UserInterface $userRepository,
|
||||
CustomerInterface $customerRepository
|
||||
) {
|
||||
$this->userRepository = $userRepository;
|
||||
$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['editable'] = false;
|
||||
toastr()->success('Hello');
|
||||
|
||||
return view('customer::customer.create', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
|
||||
|
||||
try {
|
||||
|
||||
$inputData = $request->all();
|
||||
|
||||
$this->customerRepository->create($inputData);
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
|
||||
toastr()->error($th->getMessage());
|
||||
}
|
||||
|
||||
toastr()->success('Hello');
|
||||
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['editable'] = true;
|
||||
$data['customer'] = $this->customerRepository->getCustomerById($id);
|
||||
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 {
|
||||
|
||||
$this->customerRepository->update($id, $inputData);
|
||||
|
||||
flash()->success('Customer updated succesfully');
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
|
||||
flash()->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();
|
||||
|
||||
flash()->success('Customer deleted succesfully');
|
||||
|
||||
} catch (\Throwable $th) {
|
||||
|
||||
flash()->error($th->getMessage());
|
||||
}
|
||||
|
||||
return response()->json(['status' => true, 'message' => 'Customer deleted succesfully']);
|
||||
|
||||
}
|
||||
}
|
0
Modules/Customer/app/Http/Requests/.gitkeep
Normal file
0
Modules/Customer/app/Http/Requests/.gitkeep
Normal file
0
Modules/Customer/app/Models/.gitkeep
Normal file
0
Modules/Customer/app/Models/.gitkeep
Normal file
34
Modules/Customer/app/Models/Customer.php
Normal file
34
Modules/Customer/app/Models/Customer.php
Normal file
@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Customer\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Customer extends Model
|
||||
{
|
||||
|
||||
protected $table = 'tbl_customers';
|
||||
protected $fillable = [
|
||||
'first_name',
|
||||
'last_name',
|
||||
'contact',
|
||||
'phone',
|
||||
'email',
|
||||
'address',
|
||||
'company_name',
|
||||
'company_pan',
|
||||
'company_address',
|
||||
'company_contact',
|
||||
'company_phone',
|
||||
'profile_pic',
|
||||
'remarks'
|
||||
];
|
||||
|
||||
public $appends = ['customer_name'];
|
||||
|
||||
public function getCustomerNameAttribute()
|
||||
{
|
||||
return $this->last_name ? "{$this->first_name} {$this->last_name}" : $this->first_name;
|
||||
}
|
||||
|
||||
}
|
0
Modules/Customer/app/Observers/.gitkeep
Normal file
0
Modules/Customer/app/Observers/.gitkeep
Normal file
0
Modules/Customer/app/Providers/.gitkeep
Normal file
0
Modules/Customer/app/Providers/.gitkeep
Normal file
117
Modules/Customer/app/Providers/CustomerServiceProvider.php
Normal file
117
Modules/Customer/app/Providers/CustomerServiceProvider.php
Normal 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;
|
||||
}
|
||||
}
|
49
Modules/Customer/app/Providers/RouteServiceProvider.php
Normal file
49
Modules/Customer/app/Providers/RouteServiceProvider.php
Normal 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'));
|
||||
}
|
||||
}
|
0
Modules/Customer/app/Repositories/.gitkeep
Normal file
0
Modules/Customer/app/Repositories/.gitkeep
Normal file
15
Modules/Customer/app/Repositories/CustomerInterface.php
Normal file
15
Modules/Customer/app/Repositories/CustomerInterface.php
Normal 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();
|
||||
|
||||
}
|
51
Modules/Customer/app/Repositories/CustomerRepository.php
Normal file
51
Modules/Customer/app/Repositories/CustomerRepository.php
Normal file
@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Customer\Repositories;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
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(DB::raw("IFNULL(CONCAT(first_name, ' ', last_name), first_name) AS customer_name"), 'id');
|
||||
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user