first change

This commit is contained in:
2025-07-27 17:40:56 +05:45
commit f8b9a6725b
3152 changed files with 229528 additions and 0 deletions

View File

@@ -0,0 +1,169 @@
<?php
namespace Modules\Client\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Modules\Client\Interfaces\ClientInterface;
use Modules\Client\Models\Client;
use Yajra\DataTables\Facades\DataTables;
class ClientController extends Controller
{
private $client;
public function __construct(ClientInterface $client)
{
$this->client = $client;
}
/**
* Display a listing of the resource.
*/
public function index()
{
if (request()->ajax()) {
$model = Client::query()->orderBy('order');
return DataTables::eloquent($model)
->addIndexColumn()
->setRowClass('tableRow')
->editColumn('logo', function (Client $client) {
return $client->getRawOriginal('logo') ? "<img src='{$client->logo}' alt='{$client->name}' class='rounded avatar-sm material-shadow ms-2 img-thumbnail'>" : '-';
})
->editColumn('title', function (Client $client) {
$route = route('client.show', $client->id);
$html ="<a class='link link-primary' href='{$route}'>{{ $client->name }}</a>";
return $html;
})
->editColumn('manager_name', function (Client $client) {
return $client->manager_name ?? "-";
})
->editColumn('status', function (Client $client) {
$status = $client->status ? 'Published' : 'Draft';
$color = $client->status ? 'text-success' : 'text-danger';
return "<p class='{$color}'>{$status}</p>";
})
->addColumn('action', 'client::client.datatable.action')
->rawColumns(['status', 'logo', 'action'])
->toJson();
}
return view('client::client.index', [
'title' => 'Client List',
]);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = 'Create Client';
$data['editable'] = false;
return view('client::client.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
$client = null;
$validated = $request->validate([
"name" => ["required", "string", "max:255"],
]);
$request->merge([
"company_name" => $request->name,
'order' => ($maxOrder = Client::max('order')) !== null ? ++$maxOrder : 1,
]);
try {
DB::transaction(function () use ($request, &$client) {
$input = $request->only(Client::getFillableFields());
$client = Client::create($input);
});
flash()->success("Client {$client->name} has been created");
return redirect()->route('client.index');
} catch (\Exception $e) {
flash()->error($e->getMessage());
return redirect()->back()->withInput();
}
}
/**
* Show the specified resource.
*/
public function show($id)
{
$data["title"] = "Show Client";
$data["client"] = $this->client->findById($id);
return view('client::client.show', $data);
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$data['title'] = 'Edit Client';
$data['editable'] = true;
$data["client"] = $this->client->findById($id);
return view('client::client.edit', $data);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id)
{
$validated = $request->validate([
"title" => ["required"],
]);
try {
DB::transaction(function () use ($request, $id) {
$input = $request->only(Client::getFillableFields());
$client = $this->client->update($id, $input);
});
flash()->success('Client has been updated!');
return redirect()->route('client.index');
} catch (\Throwable $th) {
flash()->error($th->getMessage());
return redirect()->back()->withInput();
}
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
DB::transaction(function () use ($id) {
$client = $this->client->delete($id);
});
return response()->json([
'status' => 200,
'message' => 'Client has been deleted!',
], 200);
} catch (\Throwable $th) {
return response()->json([
'status' => 500,
'message' => 'Failed to delete client!',
'error' => $th->getMessage(),
], 500);
}
}
}

View File

@@ -0,0 +1,10 @@
<?php
namespace Modules\Client\Interfaces;
use App\Interfaces\ModelInterface;
interface ClientInterface extends ModelInterface
{
}

View File

@@ -0,0 +1,45 @@
<?php
namespace Modules\Client\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Modules\Client\Database\Factories\ClientFactory;
use Modules\Product\Models\Product;
use Modules\User\Traits\HasActivityLogs;
class Client extends Model
{
use HasFactory, HasActivityLogs;
/**
* The attributes that are mass assignable.
*/
protected $fillable = [
'name',
'company_name',
'contact',
'logo',
'manager_name',
'manager_contact',
'poc_name',
'poc_contact',
'promised_document',
'poc_document',
'description',
'status',
'order',
'createdby',
'updatedby',
];
public function products()
{
return $this->hasMany(Product::class, 'client_id');
}
protected static function newFactory(): ClientFactory
{
return ClientFactory::new();
}
}

View File

View File

@@ -0,0 +1,138 @@
<?php
namespace Modules\Client\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Modules\Client\Interfaces\ClientInterface;
use Modules\Client\Repositories\ClientRepository;
use Nwidart\Modules\Traits\PathNamespace;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
class ClientServiceProvider extends ServiceProvider
{
use PathNamespace;
protected string $name = 'Client';
protected string $nameLower = 'client';
/**
* Boot the application events.
*/
public function boot(): void
{
$this->registerCommands();
$this->registerCommandSchedules();
$this->registerTranslations();
$this->registerConfig();
$this->registerViews();
$this->loadMigrationsFrom(module_path($this->name, 'database/migrations'));
}
/**
* Register the service provider.
*/
public function register(): void
{
$this->app->bind(ClientInterface::class, ClientRepository::class);
$this->app->register(EventServiceProvider::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->nameLower);
if (is_dir($langPath)) {
$this->loadTranslationsFrom($langPath, $this->nameLower);
$this->loadJsonTranslationsFrom($langPath);
} else {
$this->loadTranslationsFrom(module_path($this->name, 'lang'), $this->nameLower);
$this->loadJsonTranslationsFrom(module_path($this->name, 'lang'));
}
}
/**
* Register config.
*/
protected function registerConfig(): void
{
$relativeConfigPath = config('modules.paths.generator.config.path');
$configPath = module_path($this->name, $relativeConfigPath);
if (is_dir($configPath)) {
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($configPath));
foreach ($iterator as $file) {
if ($file->isFile() && $file->getExtension() === 'php') {
$relativePath = str_replace($configPath . DIRECTORY_SEPARATOR, '', $file->getPathname());
$configKey = $this->nameLower . '.' . str_replace([DIRECTORY_SEPARATOR, '.php'], ['.', ''], $relativePath);
$key = ($relativePath === 'config.php') ? $this->nameLower : $configKey;
$this->publishes([$file->getPathname() => config_path($relativePath)], 'config');
$this->mergeConfigFrom($file->getPathname(), $key);
}
}
}
}
/**
* Register views.
*/
public function registerViews(): void
{
$viewPath = resource_path('views/modules/'.$this->nameLower);
$sourcePath = module_path($this->name, 'resources/views');
$this->publishes([$sourcePath => $viewPath], ['views', $this->nameLower.'-module-views']);
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->nameLower);
$componentNamespace = $this->module_namespace($this->name, $this->app_path(config('modules.paths.generator.component-class.path')));
Blade::componentNamespace($componentNamespace, $this->nameLower);
}
/**
* 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->nameLower)) {
$paths[] = $path.'/modules/'.$this->nameLower;
}
}
return $paths;
}
}

View File

@@ -0,0 +1,30 @@
<?php
namespace Modules\Client\Providers;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
/**
* The event handler mappings for the application.
*
* @var array<string, array<int, string>>
*/
protected $listen = [];
/**
* Indicates if events should be discovered.
*
* @var bool
*/
protected static $shouldDiscoverEvents = true;
/**
* Configure the proper event listeners for email verification.
*/
protected function configureEmailVerification(): void
{
//
}
}

View File

@@ -0,0 +1,50 @@
<?php
namespace Modules\Client\Providers;
use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
class RouteServiceProvider extends ServiceProvider
{
protected string $name = 'Client';
/**
* 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($this->name, '/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($this->name, '/routes/api.php'));
}
}

View File

@@ -0,0 +1,80 @@
<?php
namespace Modules\Client\Repositories;
use Illuminate\Http\Request;
use Modules\Client\Interfaces\ClientInterface;
use Modules\Client\Models\Client;
class ClientRepository implements ClientInterface
{
public function findAll($request, callable $query = null, bool $paginate = false, int $limit = 10)
{
$baseQuery = Client::query();
if ($request->filled('search')) {
$baseQuery->whereAny(
[
'name',
'manager_name',
'poc_name',
],
'LIKE',
"%{$request->search}%"
);
}
if ($query) {
$query($baseQuery);
}
if ($paginate) {
return $baseQuery->paginate($limit);
}
return $baseQuery->get();
}
public function findById($id, callable $query = null)
{
$baseQuery = Client::query();
if (is_callable($query)) {
$query($baseQuery);
}
return $baseQuery->where('id', $id)->firstOrFail();
}
public function delete($id)
{
$client = $this->findById($id);
$client->delete();
return $client;
}
public function create(array $data)
{
$client = Client::create($data);
return $client;
}
public function update($id, array $data)
{
$client = $this->findById($id);
$client->update($data);
return $client;
}
public function pluck(callable $query = null)
{
$baseQuery = Client::query();
if (is_callable($query)) {
$query($baseQuery);
}
return $baseQuery->pluck('name', 'id');
}
}

View File