firstcommit
This commit is contained in:
0
Modules/Package/app/Http/Controllers/.gitkeep
Normal file
0
Modules/Package/app/Http/Controllers/.gitkeep
Normal file
133
Modules/Package/app/Http/Controllers/PackageController.php
Normal file
133
Modules/Package/app/Http/Controllers/PackageController.php
Normal file
@@ -0,0 +1,133 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Package\app\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
|
||||
use Modules\CountryList\app\Models\Country;
|
||||
use Modules\Package\app\Repositories\PackageRepository;
|
||||
use Modules\Package\app\Http\Requests\CreatePackageRequest;
|
||||
|
||||
class PackageController extends Controller
|
||||
{
|
||||
protected $packageRepository;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->packageRepository = new PackageRepository;
|
||||
}
|
||||
|
||||
public function index(Request $request)
|
||||
{
|
||||
$perPage = $request->has('per-page') ? $request->input('per-page') : null;
|
||||
$filter = $request->has('filter') ? $request->input('filter') : [];
|
||||
$packages = $this->packageRepository->allPackages($perPage, $filter);
|
||||
|
||||
return view('package::index', compact('packages'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$countries = $this->packageRepository->getAllCountries();
|
||||
return view('package::create', compact('countries'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(CreatePackageRequest $request): RedirectResponse
|
||||
{
|
||||
try {
|
||||
$validated = $request->validated();
|
||||
$this->packageRepository->storePackage($validated);
|
||||
|
||||
toastr()->success('Package created successfully.');
|
||||
|
||||
return redirect()->route('cms.packages.index');
|
||||
} catch (\Throwable $th) {
|
||||
report($th);
|
||||
toastr()->error('Something went wrong.');
|
||||
return back();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
return view('package::show');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit($uuid)
|
||||
{
|
||||
$data['countries'] = $this->packageRepository->getAllCountries();
|
||||
$data['package'] = $this->packageRepository->findPackageWithCountriesByUuid($uuid);
|
||||
if (!$data['package']) {
|
||||
toastr()->error('Package not found.');
|
||||
return back();
|
||||
}
|
||||
|
||||
return view('package::edit', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(CreatePackageRequest $request, $uuid): RedirectResponse
|
||||
{
|
||||
try {
|
||||
$validated = $request->validated();
|
||||
$package = $this->packageRepository->findPackageByUuid($uuid);
|
||||
|
||||
if (!$package) {
|
||||
toastr()->error('Package not found !');
|
||||
return back();
|
||||
}
|
||||
|
||||
$this->packageRepository->updatePackage(validated: $validated, uuid: $uuid);
|
||||
|
||||
toastr()->success('Package updated successfully.');
|
||||
|
||||
return redirect()->route('cms.packages.index');
|
||||
} catch (\Throwable $th) {
|
||||
report($th);
|
||||
toastr()->error('Something went wrong.');
|
||||
return back();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy($uuid)
|
||||
{
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
$package = $this->packageRepository->deletePackage(uuid: $uuid);
|
||||
if (!$package) {
|
||||
toastr()->error('Package not found.');
|
||||
return back();
|
||||
}
|
||||
DB::commit();
|
||||
|
||||
toastr()->success('Package deleted successfully.');
|
||||
|
||||
return redirect()->route('cms.packages.index');
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollback();
|
||||
report($th);
|
||||
toastr()->error('Something went wrong.');
|
||||
return back();
|
||||
}
|
||||
}
|
||||
}
|
0
Modules/Package/app/Http/Middleware/.gitkeep
Normal file
0
Modules/Package/app/Http/Middleware/.gitkeep
Normal file
0
Modules/Package/app/Http/Requests/.gitkeep
Normal file
0
Modules/Package/app/Http/Requests/.gitkeep
Normal file
34
Modules/Package/app/Http/Requests/CreatePackageRequest.php
Normal file
34
Modules/Package/app/Http/Requests/CreatePackageRequest.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Package\app\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class CreatePackageRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'title' => 'required|string',
|
||||
'description' => 'required|string',
|
||||
'country_id' => 'required',
|
||||
'price' => 'required',
|
||||
'duration' => 'required',
|
||||
'group_size' => 'required|numeric',
|
||||
'ordering' => 'required|numeric',
|
||||
'image' => 'sometimes|nullable|image|mimes:jpeg,png,jpg,gif',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
// return auth()->user()->can('users.create');
|
||||
}
|
||||
}
|
0
Modules/Package/app/Models/.gitkeep
Normal file
0
Modules/Package/app/Models/.gitkeep
Normal file
54
Modules/Package/app/Models/Package.php
Normal file
54
Modules/Package/app/Models/Package.php
Normal file
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Package\app\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Modules\CountryList\app\Models\Country;
|
||||
use Modules\Package\Database\factories\PackageFactory;
|
||||
|
||||
class Package extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected $fillable = [
|
||||
'uuid',
|
||||
'country_id',
|
||||
'title',
|
||||
'description',
|
||||
'price',
|
||||
'duration',
|
||||
'group_size',
|
||||
'ordering',
|
||||
'image',
|
||||
'image_path',
|
||||
'status',
|
||||
];
|
||||
|
||||
public function country()
|
||||
{
|
||||
return $this->belongsTo(Country::class);
|
||||
}
|
||||
|
||||
protected static function newFactory(): PackageFactory
|
||||
{
|
||||
//return PackageFactory::new();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function getFullImageAttribute()
|
||||
{
|
||||
$result = null;
|
||||
|
||||
if($this->image_path) {
|
||||
$result = asset('storage/uploads/' . $this->image_path);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
0
Modules/Package/app/Providers/.gitkeep
Normal file
0
Modules/Package/app/Providers/.gitkeep
Normal file
114
Modules/Package/app/Providers/PackageServiceProvider.php
Normal file
114
Modules/Package/app/Providers/PackageServiceProvider.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Package\app\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class PackageServiceProvider extends ServiceProvider
|
||||
{
|
||||
protected string $moduleName = 'Package';
|
||||
|
||||
protected string $moduleNameLower = 'package';
|
||||
|
||||
/**
|
||||
* 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->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.'\\'.config('modules.paths.generator.component-class.path'));
|
||||
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;
|
||||
}
|
||||
}
|
59
Modules/Package/app/Providers/RouteServiceProvider.php
Normal file
59
Modules/Package/app/Providers/RouteServiceProvider.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Package\app\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
||||
|
||||
class RouteServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* The module namespace to assume when generating URLs to actions.
|
||||
*/
|
||||
protected string $moduleNamespace = 'Modules\Package\app\Http\Controllers';
|
||||
|
||||
/**
|
||||
* 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')
|
||||
->namespace($this->moduleNamespace)
|
||||
->group(module_path('Package', '/routes/web.php'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Define the "api" routes for the application.
|
||||
*
|
||||
* These routes are typically stateless.
|
||||
*/
|
||||
protected function mapApiRoutes(): void
|
||||
{
|
||||
Route::prefix('api')
|
||||
->middleware('api')
|
||||
->namespace($this->moduleNamespace)
|
||||
->group(module_path('Package', '/routes/api.php'));
|
||||
}
|
||||
}
|
135
Modules/Package/app/Repositories/PackageRepository.php
Normal file
135
Modules/Package/app/Repositories/PackageRepository.php
Normal file
@@ -0,0 +1,135 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Package\app\Repositories;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\Package\app\Models\Package;
|
||||
use Modules\CountryList\app\Models\Country;
|
||||
use Modules\Banner\app\Services\FileManagementService;
|
||||
|
||||
class PackageRepository
|
||||
{
|
||||
//-- Retrieve all Packages
|
||||
public function allPackages($perPage = null, $filter = [], $sort = ['by' => 'id', 'sort' => 'DESC'])
|
||||
{
|
||||
return Package::when(array_keys($filter, true), function ($query) use ($filter) {
|
||||
if (!empty($filter['title'])) {
|
||||
$query->where('title', $filter['title']);
|
||||
}
|
||||
if (!empty($filter['price'])) {
|
||||
$query->where('price', 'like', '%' . $filter['price'] . '%');
|
||||
}
|
||||
})
|
||||
->orderBy($sort['by'], $sort['sort'])
|
||||
->paginate($perPage ?: env('PAGE_LIMIT', 999));
|
||||
}
|
||||
|
||||
//-- Find Package by uuid
|
||||
public function findPackageByUuid($uuid)
|
||||
{
|
||||
return Package::where('uuid', $uuid)->first();
|
||||
}
|
||||
|
||||
//-- Find Package by uuid
|
||||
public function findPackageWithCountriesByUuid($uuid)
|
||||
{
|
||||
return Package::with('country')->where('uuid', $uuid)->first();
|
||||
}
|
||||
|
||||
//-- Retrieve all countries
|
||||
public function getAllCountries()
|
||||
{
|
||||
return Country::all();
|
||||
}
|
||||
|
||||
//-- Store Package
|
||||
public function storePackage(array $validated)
|
||||
{
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
$package = new Package();
|
||||
$package->uuid = Str::uuid();
|
||||
$package->title = $validated['title'];
|
||||
$package->description = $validated['description'];
|
||||
$package->country_id = $validated['country_id'];
|
||||
$package->price = $validated['price'];
|
||||
$package->duration = $validated['duration'];
|
||||
$package->group_size = $validated['group_size'];
|
||||
$package->ordering = $validated['ordering'];
|
||||
$package->save();
|
||||
|
||||
// Check if image is uploaded and valid and store image
|
||||
if (isset($validated['image']) && $validated['image']->isValid()) {
|
||||
FileManagementService::storeFile(
|
||||
file: $validated['image'],
|
||||
uploadedFolderName: 'packages',
|
||||
model: $package
|
||||
);
|
||||
}
|
||||
DB::commit();
|
||||
|
||||
return $package;
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollback();
|
||||
report($th);
|
||||
}
|
||||
}
|
||||
|
||||
public function updatePackage(array $validated, string $uuid)
|
||||
{
|
||||
try {
|
||||
$package = $this->findPackageByUuid($uuid);
|
||||
if (!$package) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$package->title = $validated['title'];
|
||||
$package->description = $validated['description'];
|
||||
$package->country_id = $validated['country_id'];
|
||||
$package->price = $validated['price'];
|
||||
$package->duration = $validated['duration'];
|
||||
$package->group_size = $validated['group_size'];
|
||||
$package->ordering = $validated['ordering'];
|
||||
$package->save();
|
||||
|
||||
//-- Update image
|
||||
if (isset($validated['image']) && $validated['image']->isValid()) {
|
||||
FileManagementService::uploadFile(
|
||||
file: $validated['image'],
|
||||
uploadedFolderName: 'packages',
|
||||
filePath: $package->image_path,
|
||||
model: $package
|
||||
);
|
||||
}
|
||||
|
||||
return $package;
|
||||
} catch (\Throwable $th) {
|
||||
DB::transaction();
|
||||
report($th);
|
||||
}
|
||||
}
|
||||
|
||||
//-- Delete package
|
||||
public function deletePackage(string $uuid)
|
||||
{
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
$package = $this->findPackageByUuid($uuid);
|
||||
if (! $package) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Delete the image file associated with the activity
|
||||
if ($package->image_path !== null) {
|
||||
FileManagementService::deleteFile($package->image_path);
|
||||
}
|
||||
$package->delete();
|
||||
|
||||
return $package;
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollBack();
|
||||
report($th);
|
||||
}
|
||||
}
|
||||
}
|
66
Modules/Package/app/Services/FileManagementService.php
Normal file
66
Modules/Package/app/Services/FileManagementService.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Package\app\Services;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class FileManagementService
|
||||
{
|
||||
//-- store file
|
||||
public static function storeFile($file, $uploadedFolderName, $model)
|
||||
{
|
||||
try {
|
||||
$originalFileName = $file->getClientOriginalName();
|
||||
$modifiedFileName = date('YmdHis') . "_" . uniqid() . "." . $originalFileName;
|
||||
|
||||
$file->storeAs($uploadedFolderName, $modifiedFileName, 'public_uploads'); // This line uses 'public_uploads' disk
|
||||
|
||||
$model->image = $modifiedFileName;
|
||||
$model->image_path = $uploadedFolderName . '/' . $modifiedFileName;
|
||||
$model->save();
|
||||
} catch (\Throwable $th) {
|
||||
report($th);
|
||||
toastr()->error('Something went wrong.');
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
|
||||
//-- update file
|
||||
public static function uploadFile($file, $uploadedFolderName ,$filePath, $model)
|
||||
{
|
||||
try {
|
||||
if ($filePath && Storage::disk('public_uploads')->exists($filePath)) {
|
||||
Storage::disk('public_uploads')->delete($filePath);
|
||||
}
|
||||
|
||||
$originalFileName = $file->getClientOriginalName();
|
||||
$modifiedFileName = date('YmdHis') . "_" . uniqid() . "." . $originalFileName;
|
||||
|
||||
$file->storeAs($uploadedFolderName, $modifiedFileName, 'public_uploads'); // This line uses 'public_uploads' disk
|
||||
|
||||
$model->image = $modifiedFileName;
|
||||
$model->image_path = $uploadedFolderName . '/' . $modifiedFileName;
|
||||
|
||||
$model->save();
|
||||
} catch (\Throwable $th) {
|
||||
report($th);
|
||||
toastr()->error('Something went wrong.');
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-- delete file
|
||||
public static function deleteFile($filePath)
|
||||
{
|
||||
try {
|
||||
if ($filePath && Storage::disk('public_uploads')->exists($filePath)) {
|
||||
Storage::disk('public_uploads')->delete($filePath);
|
||||
} else {
|
||||
toastr()->error('File Not wrong.');
|
||||
}
|
||||
} catch (\Throwable $th) {
|
||||
report($th);
|
||||
toastr()->error('Something went wrong while deleting the file.');
|
||||
}
|
||||
}
|
||||
}
|
31
Modules/Package/composer.json
Normal file
31
Modules/Package/composer.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"name": "nwidart/package",
|
||||
"description": "",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Widart",
|
||||
"email": "n.widart@gmail.com"
|
||||
}
|
||||
],
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [],
|
||||
"aliases": {
|
||||
|
||||
}
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Modules\\Package\\": "",
|
||||
"Modules\\Package\\App\\": "app/",
|
||||
"Modules\\Package\\Database\\Factories\\": "database/factories/",
|
||||
"Modules\\Package\\Database\\Seeders\\": "database/seeders/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Modules\\Package\\Tests\\": "tests/"
|
||||
}
|
||||
}
|
||||
}
|
0
Modules/Package/config/.gitkeep
Normal file
0
Modules/Package/config/.gitkeep
Normal file
5
Modules/Package/config/config.php
Normal file
5
Modules/Package/config/config.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'name' => 'Package',
|
||||
];
|
0
Modules/Package/database/factories/.gitkeep
Normal file
0
Modules/Package/database/factories/.gitkeep
Normal file
0
Modules/Package/database/migrations/.gitkeep
Normal file
0
Modules/Package/database/migrations/.gitkeep
Normal file
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('packages', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->uuid();
|
||||
$table->unsignedBigInteger('country_id');
|
||||
$table->string('title');
|
||||
$table->text('description');
|
||||
$table->float('price', 8, 2);
|
||||
$table->string('duration');
|
||||
$table->integer('group_size');
|
||||
$table->integer('ordering');
|
||||
$table->string('image')->nullable();
|
||||
$table->string('image_path')->nullable();
|
||||
$table->string('status')->default('active');
|
||||
$table->softDeletes();
|
||||
$table->timestamps();
|
||||
|
||||
$table->foreign('country_id')->references('id')->on('countries');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('packages');
|
||||
}
|
||||
};
|
0
Modules/Package/database/seeders/.gitkeep
Normal file
0
Modules/Package/database/seeders/.gitkeep
Normal file
20
Modules/Package/database/seeders/PackageDatabaseSeeder.php
Normal file
20
Modules/Package/database/seeders/PackageDatabaseSeeder.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Package\database\seeders;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Modules\Package\app\Models\Package;
|
||||
use Modules\CountryList\app\Models\Country;
|
||||
|
||||
class PackageDatabaseSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
0
Modules/Package/lang/.gitkeep
Normal file
0
Modules/Package/lang/.gitkeep
Normal file
11
Modules/Package/module.json
Normal file
11
Modules/Package/module.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "Package",
|
||||
"alias": "package",
|
||||
"description": "",
|
||||
"keywords": [],
|
||||
"priority": 0,
|
||||
"providers": [
|
||||
"Modules\\Package\\app\\Providers\\PackageServiceProvider"
|
||||
],
|
||||
"files": []
|
||||
}
|
15
Modules/Package/package.json
Normal file
15
Modules/Package/package.json
Normal file
@@ -0,0 +1,15 @@
|
||||
{
|
||||
"private": true,
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "vite build"
|
||||
},
|
||||
"devDependencies": {
|
||||
"axios": "^1.1.2",
|
||||
"laravel-vite-plugin": "^0.7.5",
|
||||
"sass": "^1.69.5",
|
||||
"postcss": "^8.3.7",
|
||||
"vite": "^4.0.0"
|
||||
}
|
||||
}
|
0
Modules/Package/resources/assets/.gitkeep
Normal file
0
Modules/Package/resources/assets/.gitkeep
Normal file
0
Modules/Package/resources/assets/js/app.js
Normal file
0
Modules/Package/resources/assets/js/app.js
Normal file
0
Modules/Package/resources/assets/sass/app.scss
Normal file
0
Modules/Package/resources/assets/sass/app.scss
Normal file
0
Modules/Package/resources/views/.gitkeep
Normal file
0
Modules/Package/resources/views/.gitkeep
Normal file
45
Modules/Package/resources/views/create.blade.php
Normal file
45
Modules/Package/resources/views/create.blade.php
Normal file
@@ -0,0 +1,45 @@
|
||||
@extends('admin::layouts.master')
|
||||
|
||||
@section('title')
|
||||
Create Package
|
||||
@endsection
|
||||
|
||||
@section('breadcrumb')
|
||||
@php
|
||||
$breadcrumbData = [
|
||||
[
|
||||
'title' => 'Package',
|
||||
'link' => 'null',
|
||||
],
|
||||
[
|
||||
'title' => 'Dashboard',
|
||||
'link' => route('dashboard'),
|
||||
],
|
||||
[
|
||||
'title' => 'Packages',
|
||||
'link' => null,
|
||||
],
|
||||
[
|
||||
'title' => 'Add Package',
|
||||
'link' => null,
|
||||
],
|
||||
];
|
||||
@endphp
|
||||
@include('admin::layouts.partials.breadcrumb', $breadcrumbData)
|
||||
@endsection
|
||||
@section('content')
|
||||
<div class="row">
|
||||
<div class="col-xxl">
|
||||
<div class="card mb-4">
|
||||
<div class="card-header d-flex align-items-center justify-content-between">
|
||||
<h5 class="mb-0">Add Package</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form action="{{ route('cms.packages.store') }}" method="POST" enctype="multipart/form-data">
|
||||
@csrf
|
||||
@include('package::partial.form')
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
49
Modules/Package/resources/views/edit.blade.php
Normal file
49
Modules/Package/resources/views/edit.blade.php
Normal file
@@ -0,0 +1,49 @@
|
||||
@extends('admin::layouts.master')
|
||||
|
||||
@section('title')
|
||||
Update Package
|
||||
@endsection
|
||||
|
||||
@section('breadcrumb')
|
||||
@php
|
||||
$breadcrumbData = [
|
||||
[
|
||||
'title' => 'Package',
|
||||
'link' => 'null',
|
||||
],
|
||||
[
|
||||
'title' => 'Dashboard',
|
||||
'link' => route('dashboard'),
|
||||
],
|
||||
[
|
||||
'title' => 'Packages',
|
||||
'link' => null,
|
||||
],
|
||||
[
|
||||
'title' => 'Update Package',
|
||||
'link' => null,
|
||||
],
|
||||
];
|
||||
@endphp
|
||||
@include('admin::layouts.partials.breadcrumb', $breadcrumbData)
|
||||
@endsection
|
||||
@section('content')
|
||||
<div class="row">
|
||||
<div class="col-xxl">
|
||||
<div class="card mb-4">
|
||||
<div class="card-header d-flex align-items-center justify-content-between">
|
||||
<h5 class="mb-0">Update Package</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<form action="{{ route('cms.packages.update', ['uuid' => $package->uuid]) }}" method="POST"
|
||||
enctype="multipart/form-data">
|
||||
@csrf
|
||||
@method('PUT')
|
||||
|
||||
@include('package::partial.form')
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
137
Modules/Package/resources/views/index.blade.php
Normal file
137
Modules/Package/resources/views/index.blade.php
Normal file
@@ -0,0 +1,137 @@
|
||||
@extends('admin::layouts.master')
|
||||
|
||||
@section('title')
|
||||
Package
|
||||
@endsection
|
||||
|
||||
@section('breadcrumb')
|
||||
@php
|
||||
$breadcrumbData = [
|
||||
[
|
||||
'title' => 'Package',
|
||||
'link' => 'null',
|
||||
],
|
||||
[
|
||||
'title' => 'Dashboard',
|
||||
'link' => route('dashboard'),
|
||||
],
|
||||
[
|
||||
'title' => 'Packages',
|
||||
'link' => null,
|
||||
],
|
||||
];
|
||||
@endphp
|
||||
@include('admin::layouts.partials.breadcrumb', $breadcrumbData)
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
<!-- banners List Table -->
|
||||
<div class="card">
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<h4 class="card-header">List of Package</h4>
|
||||
</div>
|
||||
<div class="col-md-6">
|
||||
<div class="flex-column flex-md-row">
|
||||
<div class="dt-action-buttons text-end pt-3 px-3">
|
||||
<div class="dt-buttons btn-group flex-wrap">
|
||||
<a href="{{ route('cms.packages.create') }}"
|
||||
class="btn btn-secondary create-new btn-primary d-none d-sm-inline-block text-white">
|
||||
<i class="bx bx-plus me-sm-1"></i>
|
||||
Add New
|
||||
</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card-datatable table-responsive">
|
||||
<table class="datatables-users table border-top">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>S.N</th>
|
||||
<th>Image</th>
|
||||
<th>Title</th>
|
||||
<th>Country</th>
|
||||
<th>Price</th>
|
||||
<th>Days</th>
|
||||
<th>People</th>
|
||||
<th>Ordering</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody class="table-border-bottom-0">
|
||||
@foreach ($packages ?? [] as $package)
|
||||
<tr>
|
||||
<td>
|
||||
#{{ $loop->iteration }}
|
||||
</td>
|
||||
<td>
|
||||
<img class="object-fit-contain"
|
||||
src="{{ asset($package->image_path ? 'storage/uploads/' . $package->image_path : 'backend/uploads/images/no-Image.jpg') }}"
|
||||
alt="" srcset="" height="70" width="60">
|
||||
</td>
|
||||
<td>
|
||||
{{ $package->title }}
|
||||
</td>
|
||||
<td>
|
||||
{{ $package->country->name }}
|
||||
</td>
|
||||
<td>
|
||||
{{ $package->price }}
|
||||
</td>
|
||||
<td>
|
||||
{{ $package->duration }}
|
||||
</td>
|
||||
<td>
|
||||
{{ $package->group_size }}
|
||||
</td>
|
||||
<td>
|
||||
{{ $package->ordering }}
|
||||
</td>
|
||||
<td>
|
||||
<div class="dropdown">
|
||||
<button type="button" class="btn p-0 dropdown-toggle hide-arrow"
|
||||
data-bs-toggle="dropdown">
|
||||
<i class="bx bx-dots-vertical-rounded"></i>
|
||||
</button>
|
||||
<div class="dropdown-menu">
|
||||
<a class="dropdown-item"
|
||||
href="{{ route('cms.packages.edit', ['uuid' => $package->uuid]) }}"><i
|
||||
class="bx bx-edit-alt me-1"></i>
|
||||
Edit</a>
|
||||
|
||||
|
||||
<form method="POST"
|
||||
action="{{ route('cms.packages.delete', ['uuid' => $package->uuid]) }}"
|
||||
id="deleteForm_{{ $package->uuid }}" class="dropdown-item">
|
||||
@csrf
|
||||
@method('DELETE')
|
||||
<button type="submit" class="border-0 bg-transparent deleteBtn"
|
||||
style="color:inherit"><i class="bx bx-trash me-1"></i> Delete</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="px-3">
|
||||
{{ $packages->links('admin::layouts.partials.pagination') }}
|
||||
</div>
|
||||
</div>
|
||||
@endsection
|
||||
|
||||
{{-- style --}}
|
||||
@push('required-styles')
|
||||
@include('admin::vendor.dataTables.style')
|
||||
@endpush
|
||||
|
||||
{{-- script --}}
|
||||
@push('required-scripts')
|
||||
@include('admin::vendor.dataTables.script')
|
||||
@endpush
|
29
Modules/Package/resources/views/layouts/master.blade.php
Normal file
29
Modules/Package/resources/views/layouts/master.blade.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
|
||||
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
<meta name="csrf-token" content="{{ csrf_token() }}">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
|
||||
<title>Package Module - {{ config('app.name', 'Laravel') }}</title>
|
||||
|
||||
<meta name="description" content="{{ $description ?? '' }}">
|
||||
<meta name="keywords" content="{{ $keywords ?? '' }}">
|
||||
<meta name="author" content="{{ $author ?? '' }}">
|
||||
|
||||
<!-- Fonts -->
|
||||
<link rel="preconnect" href="https://fonts.bunny.net">
|
||||
<link href="https://fonts.bunny.net/css?family=figtree:400,500,600&display=swap" rel="stylesheet" />
|
||||
|
||||
{{-- Vite CSS --}}
|
||||
{{-- {{ module_vite('build-package', 'resources/assets/sass/app.scss') }} --}}
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@yield('content')
|
||||
|
||||
{{-- Vite JS --}}
|
||||
{{-- {{ module_vite('build-package', 'resources/assets/js/app.js') }} --}}
|
||||
</body>
|
98
Modules/Package/resources/views/partial/form.blade.php
Normal file
98
Modules/Package/resources/views/partial/form.blade.php
Normal file
@@ -0,0 +1,98 @@
|
||||
<div>
|
||||
<div class="row mb-4">
|
||||
<div class="card-body">
|
||||
<div class="d-flex align-items-start align-items-sm-center gap-4">
|
||||
<img src="{{ asset(!empty($package->image_path) ? 'storage/uploads/' . $package->image_path : 'backend/uploads/images/no-Image.jpg') }}"
|
||||
alt="package-image input-file" class="d-block rounded show-image" height="100" width="100" />
|
||||
<div class="button-wrapper">
|
||||
<label for="upload" class="btn btn-primary me-2 mb-4" tabindex="0">
|
||||
<span class="d-none d-sm-block">Upload</span>
|
||||
<i class="bx bx-upload d-block d-sm-none"></i>
|
||||
<input type="file" id="upload" class="input-file" name="image" hidden
|
||||
accept="image/png, image/jpeg" />
|
||||
</label>
|
||||
<button type="button" class="btn btn-label-secondary image-reset mb-4">
|
||||
<i class="bx bx-reset d-block d-sm-none"></i>
|
||||
<span class="d-none d-sm-block">Reset</span>
|
||||
</button>
|
||||
|
||||
<p class="mb-0">Allowed JPG, GIF or PNG. Max size of 3Mb</p>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<hr class="my-0" />
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="mb-3 col-md-6">
|
||||
<label class="form-label" for="basic-default-name">Title</label>
|
||||
<input type="text" class="form-control" name="title" value="{{ old('title', $package->title ?? '') }}"
|
||||
placeholder="e.g. 2 Days Italy Road Trip (Couple)" required />
|
||||
</div>
|
||||
<div class="mb-3 col-md-6">
|
||||
<label class="form-label" for="basic-default-company">Country</label>
|
||||
<select id="select2Basic" class="select2 form-select form-select-lg" name="country_id"
|
||||
data-allow-clear="true">
|
||||
@foreach ($countries ?? [] as $country)
|
||||
<option value="{{ $country->id }}"
|
||||
{{ ($package->country_id ?? '') == $country->id ? 'selected' : '' }}>{{ $country->name }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="mb-3">
|
||||
<label class="form-label" for="basic-default-message">Description</label>
|
||||
<textarea name="" id="mainTextarea" class="d-none">{{ !empty($package) ? $package->description : '' }}</textarea>
|
||||
<textarea name="description" class="form-control full-editor" id="editorTextarea" rows='10'
|
||||
placeholder="Algarve’s Benagil Cave beach is one of those extra special ones.
|
||||
The only way in is by kayaking or paddle boating, which obviously adds a more
|
||||
elusive touch to this already amazing place. ....."></textarea>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="mb-3 col-md-6">
|
||||
<label class="form-label" for="basic-default-company">Price</label>
|
||||
<input class="form-control" type="text" name="price" value="{{ old('price', $package->price ?? '') }}"
|
||||
placeholder="e.g. 25000.00" required />
|
||||
</div>
|
||||
<div class="mb-3 col-md-6">
|
||||
<label class="form-label" for="basic-default-company">Ordering</label>
|
||||
<input class="form-control" type="number" name="ordering"
|
||||
value="{{ old('ordering', $package->ordering ?? '') }}" placeholder="e.g. 2" required />
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="mb-3 col-md-6">
|
||||
<label class="form-label" for="basic-default-company">Duration</label>
|
||||
<input class="form-control" type="text" name="duration"
|
||||
value="{{ old('duration', $package->duration ?? '') }}" placeholder="e.g. 10" required />
|
||||
</div>
|
||||
<div class="mb-3 col-md-6">
|
||||
<label class="form-label" for="basic-default-company">Group Size</label>
|
||||
<input class="form-control" type="number" name="group_size"
|
||||
value="{{ old('group_size', $package->group_size ?? '') }}" placeholder="e.g. 10" required />
|
||||
</div>
|
||||
</div>
|
||||
<div>
|
||||
<button type="submit" class="btn btn-primary">
|
||||
@if (empty($package))
|
||||
Save Package
|
||||
@else
|
||||
Update Package
|
||||
@endif
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@push('required-styles')
|
||||
@include('admin::vendor.full_editor.style')
|
||||
@include('admin::vendor.select2.style')
|
||||
@endpush
|
||||
|
||||
@push('required-scripts')
|
||||
@include('admin::vendor.textareaContentDisplay.script')
|
||||
@include('admin::vendor.full_editor.script')
|
||||
@include('admin::vendor.select2.script')
|
||||
@endpush
|
0
Modules/Package/routes/.gitkeep
Normal file
0
Modules/Package/routes/.gitkeep
Normal file
19
Modules/Package/routes/api.php
Normal file
19
Modules/Package/routes/api.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| API Routes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here is where you can register API routes for your application. These
|
||||
| routes are loaded by the RouteServiceProvider within a group which
|
||||
| is assigned the "api" middleware group. Enjoy building your API!
|
||||
|
|
||||
*/
|
||||
|
||||
Route::middleware(['auth:sanctum'])->prefix('v1')->name('api.')->group(function () {
|
||||
Route::get('package', fn (Request $request) => $request->user())->name('package');
|
||||
});
|
40
Modules/Package/routes/web.php
Normal file
40
Modules/Package/routes/web.php
Normal file
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Modules\Package\app\Http\Controllers\PackageController;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Web Routes
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| Here is where you can register web routes for your application. These
|
||||
| routes are loaded by the RouteServiceProvider within a group which
|
||||
| contains the "web" middleware group. Now create something great!
|
||||
|
|
||||
*/
|
||||
|
||||
Route::group(
|
||||
[
|
||||
'prefix' => 'apanel',
|
||||
'middleware' => ['auth'],
|
||||
'as' => 'cms.',
|
||||
],
|
||||
function () {
|
||||
Route::group(
|
||||
[
|
||||
'prefix' => 'cms',
|
||||
'as' => 'packages.',
|
||||
'controller' => 'PackageController',
|
||||
],
|
||||
function () {
|
||||
Route::get('packages', 'index')->name('index');
|
||||
Route::get('packages/create', 'create')->name('create');
|
||||
Route::post('packages/store', 'store')->name('store');
|
||||
Route::get('packages/{uuid}/edit', 'edit')->name('edit');
|
||||
Route::put('packages/{uuid}/update', 'update')->name('update');
|
||||
Route::delete('packages/{uuid}/delete', 'destroy')->name('delete');
|
||||
}
|
||||
);
|
||||
}
|
||||
);
|
0
Modules/Package/tests/Feature/.gitkeep
Normal file
0
Modules/Package/tests/Feature/.gitkeep
Normal file
0
Modules/Package/tests/Unit/.gitkeep
Normal file
0
Modules/Package/tests/Unit/.gitkeep
Normal file
26
Modules/Package/vite.config.js
Normal file
26
Modules/Package/vite.config.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import { defineConfig } from 'vite';
|
||||
import laravel from 'laravel-vite-plugin';
|
||||
|
||||
export default defineConfig({
|
||||
build: {
|
||||
outDir: '../../public/build-package',
|
||||
emptyOutDir: true,
|
||||
manifest: true,
|
||||
},
|
||||
plugins: [
|
||||
laravel({
|
||||
publicDirectory: '../../public',
|
||||
buildDirectory: 'build-package',
|
||||
input: [
|
||||
__dirname + '/resources/assets/sass/app.scss',
|
||||
__dirname + '/resources/assets/js/app.js'
|
||||
],
|
||||
refresh: true,
|
||||
}),
|
||||
],
|
||||
});
|
||||
|
||||
//export const paths = [
|
||||
// 'Modules/$STUDLY_NAME$/resources/assets/sass/app.scss',
|
||||
// 'Modules/$STUDLY_NAME$/resources/assets/js/app.js',
|
||||
//];
|
Reference in New Issue
Block a user