firstcommit
This commit is contained in:
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Transformation\app\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Modules\Transformation\app\Http\Requests\TransformationRequest;
|
||||
use Modules\Transformation\app\Repositories\TransformationRepository;
|
||||
|
||||
class TransformationController extends Controller
|
||||
{
|
||||
protected $transformationRepo;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->transformationRepo = new TransformationRepository();
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$perPage = $request->has('per-page') ? $request->input('per-page') : null;
|
||||
$filter = $request->has('filter') ? $request->input('filter') : [];
|
||||
$data['transformations'] = $this->transformationRepo->findAll($perPage, $filter);
|
||||
|
||||
return view('transformation::index', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$data = [];
|
||||
|
||||
return view('transformation::create', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(TransformationRequest $request): RedirectResponse
|
||||
{
|
||||
try {
|
||||
$validated = $request->validated();
|
||||
|
||||
$this->transformationRepo->create($validated);
|
||||
toastr()->success('Data created successfully.');
|
||||
|
||||
return redirect()->route('transformation.index');
|
||||
} catch (\Throwable $th) {
|
||||
report($th);
|
||||
toastr()->error('Something went wrong.');
|
||||
|
||||
return back();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
return view('transformation::show');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$data['transformation'] = $this->transformationRepo->findById($id);
|
||||
if (!$data['transformation']) {
|
||||
toastr()->error('transformation not found');
|
||||
return back();
|
||||
}
|
||||
|
||||
return view('transformation::edit', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update($id, TransformationRequest $request): RedirectResponse
|
||||
{
|
||||
try {
|
||||
$validated = $request->validated();
|
||||
$transformation = $this->transformationRepo->update($id, $validated);
|
||||
if (!$transformation) {
|
||||
toastr()->error('transformation not found');
|
||||
return back();
|
||||
}
|
||||
toastr()->success('Data updated successfully.');
|
||||
|
||||
return redirect()->route('transformation.index');
|
||||
} catch (\Throwable $th) {
|
||||
report($th);
|
||||
toastr()->error('Oops! Something went wrong.');
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
try {
|
||||
$transformation = $this->transformationRepo->delete($id);
|
||||
if (!$transformation) {
|
||||
toastr()->error('transformation not found');
|
||||
|
||||
return back();
|
||||
}
|
||||
toastr()->success('Data deleted successfully.');
|
||||
} catch (\Throwable $th) {
|
||||
report($th);
|
||||
toastr()->error('Oops! Something went wrong.');
|
||||
}
|
||||
|
||||
return redirect()->back();
|
||||
}
|
||||
}
|
0
Modules/Transformation/app/Http/Middleware/.gitkeep
Normal file
0
Modules/Transformation/app/Http/Middleware/.gitkeep
Normal file
0
Modules/Transformation/app/Http/Requests/.gitkeep
Normal file
0
Modules/Transformation/app/Http/Requests/.gitkeep
Normal file
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Transformation\app\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class TransformationRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'before' => 'sometimes|nullable|image|mimes:jpeg,png,jpg,gif',
|
||||
'after' => 'sometimes|nullable|image|mimes:jpeg,png,jpg,gif',
|
||||
// 'name' => 'required|nullable|string|max:255|regex:/^(?![ .]+$)(?!\.)(?!.*[. ])[a-zA-Z. ]+$/',
|
||||
'grade' => 'sometimes|nullable|string',
|
||||
'graft' => 'sometimes|nullable|string'
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'before.image' => 'The before image must be an image file.',
|
||||
'before.mimes' => 'The before image must be a file of type: jpeg, png, jpg, gif.',
|
||||
|
||||
'after.image' => 'The after image must be an image file.',
|
||||
'after.mimes' => 'The after image must be a file of type: jpeg, png, jpg, gif.',
|
||||
|
||||
// 'name.required' => 'The name field is required.',
|
||||
// 'name.string' => 'The name field must be a string.',
|
||||
// 'name.max' => 'The name may not be greater than 255 characters.',
|
||||
// 'name.regex' => 'The name field only accepts letters, spaces, and dots.',
|
||||
|
||||
'grade.string' => 'The grade field must be a string.',
|
||||
|
||||
'graft.string' => 'The graft field must be a string.',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
0
Modules/Transformation/app/Models/.gitkeep
Normal file
0
Modules/Transformation/app/Models/.gitkeep
Normal file
46
Modules/Transformation/app/Models/Transformation.php
Normal file
46
Modules/Transformation/app/Models/Transformation.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Transformation\app\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Transformation extends Model
|
||||
{
|
||||
const FILE_PATH = 'uploads/transformations/';
|
||||
|
||||
protected $fillable = [
|
||||
'before',
|
||||
'after',
|
||||
'name',
|
||||
'grade',
|
||||
'graft'
|
||||
];
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function getBeforeImageAttribute()
|
||||
{
|
||||
$result = null;
|
||||
|
||||
if($this->before) {
|
||||
$result = asset('storage/' . Self::FILE_PATH . $this->before);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function getAfterImageAttribute()
|
||||
{
|
||||
$result = null;
|
||||
|
||||
if($this->after) {
|
||||
$result = asset('storage/' . Self::FILE_PATH . $this->after);
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
0
Modules/Transformation/app/Providers/.gitkeep
Normal file
0
Modules/Transformation/app/Providers/.gitkeep
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Transformation\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\Transformation\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('Transformation', '/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('Transformation', '/routes/api.php'));
|
||||
}
|
||||
}
|
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Transformation\app\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class TransformationServiceProvider extends ServiceProvider
|
||||
{
|
||||
protected string $moduleName = 'Transformation';
|
||||
|
||||
protected string $moduleNameLower = 'transformation';
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
@@ -0,0 +1,155 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Transformation\app\Repositories;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Modules\Transformation\app\Models\Transformation;
|
||||
|
||||
class TransformationRepository
|
||||
{
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function findAll($perPage = null, $filter = [], $sort = ['by' => 'id', 'sort' => 'DESC'])
|
||||
{
|
||||
return Transformation::when(array_keys($filter, true), function ($query) use ($filter) {
|
||||
if (!empty($filter['name'])) {
|
||||
$query->where('name', 'like', '%' . $filter['name'] . '%');
|
||||
}
|
||||
})
|
||||
->orderBy($sort['by'], $sort['sort'])
|
||||
->paginate($perPage ?: env('PAGE_LIMIT', 999));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function findById($id)
|
||||
{
|
||||
return Transformation::where('id', $id)->first();
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function create(array $data)
|
||||
{
|
||||
$result = false;
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
try {
|
||||
if (isset($data['before'])) {
|
||||
$data['before'] = $this->upload($data['before']);
|
||||
}
|
||||
if (isset($data['after'])) {
|
||||
$data['after'] = $this->upload($data['after']);
|
||||
}
|
||||
|
||||
$result = Transformation::create($data);
|
||||
if ($result) {
|
||||
DB::commit();
|
||||
}
|
||||
} catch (\Throwable $th) {
|
||||
report($th);
|
||||
DB::rollback();
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function update($id, array $data)
|
||||
{
|
||||
$result = false;
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
try {
|
||||
$model = $this->findById($id);
|
||||
|
||||
$oldBefore = $model->before;
|
||||
$oldAfter = $model->after;
|
||||
|
||||
if (isset($data['before'])) {
|
||||
if (!is_null($oldBefore)) {
|
||||
$this->remove($oldBefore);
|
||||
}
|
||||
$data['before'] = $this->upload($data['before']);
|
||||
}
|
||||
|
||||
if (isset($data['after'])) {
|
||||
if (!is_null($oldAfter)) {
|
||||
$this->remove($oldAfter);
|
||||
}
|
||||
$data['after'] = $this->upload($data['after']);
|
||||
}
|
||||
|
||||
$result = $model->update($data);
|
||||
if ($result) {
|
||||
DB::commit();
|
||||
}
|
||||
} catch (\Throwable $th) {
|
||||
report($th);
|
||||
DB::rollback();
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function delete($id)
|
||||
{
|
||||
$result = false;
|
||||
|
||||
DB::beginTransaction();
|
||||
|
||||
try {
|
||||
$model = $this->findById($id);
|
||||
$oldBefore = $model->before;
|
||||
$oldAfter = $model->after;
|
||||
|
||||
$result = $model->delete();
|
||||
if ($result) {
|
||||
$this->remove($oldBefore);
|
||||
$this->remove($oldAfter);
|
||||
DB::commit();
|
||||
}
|
||||
} catch (\Throwable $th) {
|
||||
report($th);
|
||||
DB::rollback();
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function upload($file)
|
||||
{
|
||||
$fileExtension = $file->getClientOriginalExtension();
|
||||
$fileName = 'IMG' . time() . '_' . uniqid() . '.' . $fileExtension;
|
||||
$file->move(storage_path() . '/app/public/' . Transformation::FILE_PATH, $fileName);
|
||||
|
||||
return $fileName;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
public function remove($fileName)
|
||||
{
|
||||
$fullFilePath = storage_path() . '/app/public/' . Transformation::FILE_PATH . $fileName;
|
||||
if (file_exists($fullFilePath)) {
|
||||
unlink($fullFilePath);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
31
Modules/Transformation/composer.json
Normal file
31
Modules/Transformation/composer.json
Normal file
@@ -0,0 +1,31 @@
|
||||
{
|
||||
"name": "nwidart/transformation",
|
||||
"description": "",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Nicolas Widart",
|
||||
"email": "n.widart@gmail.com"
|
||||
}
|
||||
],
|
||||
"extra": {
|
||||
"laravel": {
|
||||
"providers": [],
|
||||
"aliases": {
|
||||
|
||||
}
|
||||
}
|
||||
},
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Modules\\Transformation\\": "",
|
||||
"Modules\\Transformation\\App\\": "app/",
|
||||
"Modules\\Transformation\\Database\\Factories\\": "database/factories/",
|
||||
"Modules\\Transformation\\Database\\Seeders\\": "database/seeders/"
|
||||
}
|
||||
},
|
||||
"autoload-dev": {
|
||||
"psr-4": {
|
||||
"Modules\\Transformation\\Tests\\": "tests/"
|
||||
}
|
||||
}
|
||||
}
|
0
Modules/Transformation/config/.gitkeep
Normal file
0
Modules/Transformation/config/.gitkeep
Normal file
5
Modules/Transformation/config/config.php
Normal file
5
Modules/Transformation/config/config.php
Normal file
@@ -0,0 +1,5 @@
|
||||
<?php
|
||||
|
||||
return [
|
||||
'name' => 'Transformation',
|
||||
];
|
0
Modules/Transformation/database/factories/.gitkeep
Normal file
0
Modules/Transformation/database/factories/.gitkeep
Normal file
0
Modules/Transformation/database/migrations/.gitkeep
Normal file
0
Modules/Transformation/database/migrations/.gitkeep
Normal file
@@ -0,0 +1,32 @@
|
||||
<?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('transformations', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('before')->nullable();
|
||||
$table->string('after')->nullable();
|
||||
$table->string('name')->nullable();
|
||||
$table->string('grade')->nullable();
|
||||
$table->string('graft')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('transformations');
|
||||
}
|
||||
};
|
0
Modules/Transformation/database/seeders/.gitkeep
Normal file
0
Modules/Transformation/database/seeders/.gitkeep
Normal file
@@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Transformation\database\seeders;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
use Modules\Transformation\app\Models\Transformation;
|
||||
|
||||
class TransformationDatabaseSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
$transformations = [
|
||||
[
|
||||
'name' => 'Jane Smith',
|
||||
'grade' => '05',
|
||||
'graft' => '3,000',
|
||||
'before' => 'before.png',
|
||||
'after' => 'after.png',
|
||||
],
|
||||
[
|
||||
'name' => 'Alex Johnson',
|
||||
'grade' => '04',
|
||||
'graft' => '2,800',
|
||||
'before' => 'before.png',
|
||||
'after' => 'after.png',
|
||||
],
|
||||
[
|
||||
'name' => 'Emily Brown',
|
||||
'grade' => '06',
|
||||
'graft' => '3,200',
|
||||
'before' => 'before.png',
|
||||
'after' => 'after.png',
|
||||
],
|
||||
[
|
||||
'name' => 'Michael Davis',
|
||||
'grade' => '02',
|
||||
'graft' => '2,200',
|
||||
'before' => 'before.png',
|
||||
'after' => 'after.png',
|
||||
],
|
||||
];
|
||||
|
||||
foreach ($transformations as $transformation) {
|
||||
$transformationData = Transformation::create([
|
||||
'name' => $transformation['name'],
|
||||
'grade' => $transformation['grade'],
|
||||
'graft' => $transformation['graft'],
|
||||
]);
|
||||
|
||||
// Add image to the created banner
|
||||
$this->uploadImageForBeforeTransformation($transformation['before'], $transformationData);
|
||||
$this->uploadImageForAfterTransformation($transformation['after'], $transformationData);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-- Upload Before transformation
|
||||
private function uploadImageForBeforeTransformation(string $imageFileName, $transformation)
|
||||
{
|
||||
|
||||
$seederDirPath = 'transformations/';
|
||||
|
||||
// Generate a unique filename for the new image
|
||||
$newFileName = Str::uuid() . '.jpg';
|
||||
|
||||
// Storage path for the new image
|
||||
$storagePath = '/transformations/' . $newFileName;
|
||||
// $storagePath = $newFileName;
|
||||
|
||||
// Check if the image exists in the seeder_disk
|
||||
if (Storage::disk('seeder_disk')->exists($seederDirPath . $imageFileName)) {
|
||||
// Copy the image from seeder to public
|
||||
$fileContents = Storage::disk('seeder_disk')->get($seederDirPath . $imageFileName);
|
||||
|
||||
Storage::disk('public_uploads')->put($storagePath, $fileContents);
|
||||
|
||||
$transformation->before = $newFileName;
|
||||
$transformation->save();
|
||||
}
|
||||
}
|
||||
|
||||
//-- Upload After transformation
|
||||
private function uploadImageForAfterTransformation(string $imageFileName, $transformation)
|
||||
{
|
||||
$seederDirPath = 'transformations/';
|
||||
|
||||
// Generate a unique filename for the new image
|
||||
$newFileName = Str::uuid() . '.jpg';
|
||||
|
||||
// Storage path for the new image
|
||||
$storagePath = '/transformations/' . $newFileName;
|
||||
|
||||
// Check if the image exists in the seeder_disk
|
||||
if (Storage::disk('seeder_disk')->exists($seederDirPath . $imageFileName)) {
|
||||
// Copy the image from seeder to public
|
||||
$fileContents = Storage::disk('seeder_disk')->get($seederDirPath . $imageFileName);
|
||||
|
||||
Storage::disk('public_uploads')->put($storagePath, $fileContents);
|
||||
|
||||
$transformation->after = $newFileName;
|
||||
$transformation->save();
|
||||
}
|
||||
}
|
||||
}
|
0
Modules/Transformation/lang/.gitkeep
Normal file
0
Modules/Transformation/lang/.gitkeep
Normal file
11
Modules/Transformation/module.json
Normal file
11
Modules/Transformation/module.json
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"name": "Transformation",
|
||||
"alias": "transformation",
|
||||
"description": "",
|
||||
"keywords": [],
|
||||
"priority": 0,
|
||||
"providers": [
|
||||
"Modules\\Transformation\\app\\Providers\\TransformationServiceProvider"
|
||||
],
|
||||
"files": []
|
||||
}
|
15
Modules/Transformation/package.json
Normal file
15
Modules/Transformation/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/Transformation/resources/assets/.gitkeep
Normal file
0
Modules/Transformation/resources/assets/.gitkeep
Normal file
0
Modules/Transformation/resources/assets/js/app.js
Normal file
0
Modules/Transformation/resources/assets/js/app.js
Normal file
0
Modules/Transformation/resources/views/.gitkeep
Normal file
0
Modules/Transformation/resources/views/.gitkeep
Normal file
38
Modules/Transformation/resources/views/create.blade.php
Normal file
38
Modules/Transformation/resources/views/create.blade.php
Normal file
@@ -0,0 +1,38 @@
|
||||
@extends('admin::layouts.master')
|
||||
|
||||
@section('title')
|
||||
Create Transformation
|
||||
@endsection
|
||||
|
||||
@section('breadcrumb')
|
||||
@php
|
||||
$breadcrumbData = [
|
||||
[
|
||||
'title' => 'Create',
|
||||
'link' => 'null',
|
||||
],
|
||||
[
|
||||
'title' => 'Dashboard',
|
||||
'link' => route('dashboard'),
|
||||
],
|
||||
[
|
||||
'title' => 'Transformations',
|
||||
'link' => route('transformation.index'),
|
||||
],
|
||||
[
|
||||
'title' => 'Create',
|
||||
'link' => null,
|
||||
],
|
||||
];
|
||||
@endphp
|
||||
@include('admin::layouts.partials.breadcrumb', $breadcrumbData)
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
|
||||
<form action="{{ route('transformation.store') }}" method="POST" enctype="multipart/form-data">
|
||||
@csrf
|
||||
@include('transformation::partial.form')
|
||||
</form>
|
||||
|
||||
@endsection
|
39
Modules/Transformation/resources/views/edit.blade.php
Normal file
39
Modules/Transformation/resources/views/edit.blade.php
Normal file
@@ -0,0 +1,39 @@
|
||||
@extends('admin::layouts.master')
|
||||
|
||||
@section('title')
|
||||
Update Transformation
|
||||
@endsection
|
||||
|
||||
@section('breadcrumb')
|
||||
@php
|
||||
$breadcrumbData = [
|
||||
[
|
||||
'title' => 'Transformation',
|
||||
'link' => 'null',
|
||||
],
|
||||
[
|
||||
'title' => 'Dashboard',
|
||||
'link' => route('dashboard'),
|
||||
],
|
||||
[
|
||||
'title' => 'Transformations',
|
||||
'link' => route('transformation.index'),
|
||||
],
|
||||
[
|
||||
'title' => 'Update',
|
||||
'link' => null,
|
||||
],
|
||||
];
|
||||
@endphp
|
||||
@include('admin::layouts.partials.breadcrumb', $breadcrumbData)
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
|
||||
<form action="{{ route('transformation.update', ['id' => $transformation->id]) }}" method="POST" enctype="multipart/form-data">
|
||||
@csrf
|
||||
@method('put')
|
||||
@include('transformation::partial.form', $transformation)
|
||||
</form>
|
||||
|
||||
@endsection
|
120
Modules/Transformation/resources/views/index.blade.php
Normal file
120
Modules/Transformation/resources/views/index.blade.php
Normal file
@@ -0,0 +1,120 @@
|
||||
@extends('admin::layouts.master')
|
||||
|
||||
@section('title')
|
||||
Transformations
|
||||
@endsection
|
||||
|
||||
@section('breadcrumb')
|
||||
@php
|
||||
$breadcrumbData = [
|
||||
[
|
||||
'title' => 'Transformations',
|
||||
'link' => 'null',
|
||||
],
|
||||
[
|
||||
'title' => 'Dashboard',
|
||||
'link' => route('dashboard'),
|
||||
],
|
||||
[
|
||||
'title' => 'Transformations',
|
||||
'link' => null,
|
||||
],
|
||||
];
|
||||
@endphp
|
||||
@include('admin::layouts.partials.breadcrumb', $breadcrumbData)
|
||||
@endsection
|
||||
|
||||
@section('content')
|
||||
|
||||
<div class="card">
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<h4 class="card-header">List of Transformation</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('transformation.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 table-hover border-top">
|
||||
<thead class="table-light">
|
||||
<tr>
|
||||
<th>S.N</th>
|
||||
<th>Title With Image</th>
|
||||
<th>Hair Loss Grade</th>
|
||||
<th>No. of Grafts</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="table-border-bottom-0">
|
||||
@if(count($transformations) > 0)
|
||||
@foreach ($transformations ?? [] as $transformation)
|
||||
<tr>
|
||||
<td>
|
||||
#{{ $loop->iteration }}
|
||||
</td>
|
||||
<td>
|
||||
<div class="d-flex align-items-center me-3">
|
||||
<img src="{{ $transformation->beforeImage }}" alt="Image" class="rounded-circle me-3" height="40" width="40" style="object-fit: cover">
|
||||
<img src="{{ $transformation->afterImage }}" alt="Image" class="rounded-circle me-3" height="40" width="40" style="object-fit: cover">
|
||||
<div class="card-title mb-0">
|
||||
<h6 class="mb-0">{{ $transformation->name }}</h6>
|
||||
<small class="text-muted">{{ Str::limit('Patient', 80) }}</small>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
{{ $transformation->grade }}
|
||||
</td>
|
||||
<td>
|
||||
{{ $transformation->graft }}
|
||||
</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('transformation.edit', ['id' => $transformation->id]) }}"><i
|
||||
class="bx bx-edit-alt me-1"></i>
|
||||
Edit</a>
|
||||
<form method="POST"
|
||||
action="{{ route('transformation.delete', ['id' => $transformation->id]) }}"
|
||||
id="deleteForm_{{ $transformation->id }}" 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
|
||||
@else
|
||||
<tr>
|
||||
<td colspan="5">No records found.</td>
|
||||
</tr>
|
||||
@endif
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<div class="px-3">
|
||||
{{ $transformations->links('admin::layouts.partials.pagination') }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@endsection
|
@@ -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>Transformation 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-transformation', 'resources/assets/sass/app.scss') }} --}}
|
||||
</head>
|
||||
|
||||
<body>
|
||||
@yield('content')
|
||||
|
||||
{{-- Vite JS --}}
|
||||
{{-- {{ module_vite('build-transformation', 'resources/assets/js/app.js') }} --}}
|
||||
</body>
|
@@ -0,0 +1,98 @@
|
||||
@push('required-styles')
|
||||
@include('admin::vendor.select2.style')
|
||||
@endpush
|
||||
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<div class="row">
|
||||
<div class="col-12">
|
||||
<h6 class="fw-normal">1. Basic Details</h6>
|
||||
<hr class="mt-0">
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<div class="row">
|
||||
<div class="col-md-6">
|
||||
<div class="d-flex align-items-start align-items-sm-center gap-4">
|
||||
<img src="{{ isset($transformation->before) ? $transformation->beforeImage : asset('backend/uploads/images/no-Image.jpg') }}"
|
||||
alt="destination-image input-file" class="d-block rounded show-image" height="100"
|
||||
width="100" />
|
||||
<div class="button-wrapper">
|
||||
<label for="upload" class="btn btn-primary btn-sm me-2 mb-4" tabindex="0">
|
||||
<span class="d-none d-sm-block">Upload Before Image</span>
|
||||
<i class="bx bx-upload d-block d-sm-none"></i>
|
||||
<input type="file" id="upload" class="input-file" name="before" hidden
|
||||
accept="image/png, image/jpeg" />
|
||||
</label>
|
||||
<button type="button" class="btn btn-label-secondary btn-sm 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>
|
||||
<div class="col-md-6">
|
||||
<div class="d-flex align-items-start align-items-sm-center gap-4">
|
||||
<img src="{{ asset(!empty($transformation->after) ? $transformation->afterImage : 'backend/uploads/images/no-Image.jpg') }}"
|
||||
alt="site-image input-file" class="d-block rounded show-secondary" height="100"
|
||||
width="100" />
|
||||
<div class="button-wrapper">
|
||||
<label for="uploadSecondary" class="btn btn-primary btn-sm me-2 mb-4" tabindex="0">
|
||||
<span class="d-none d-sm-block">Upload After Image</span>
|
||||
<i class="bx bx-upload d-block d-sm-none"></i>
|
||||
<input type="file" id="uploadSecondary" class="input-secondary" name="after"
|
||||
hidden accept="image/png, image/jpeg" />
|
||||
</label>
|
||||
<button type="button" class="btn btn-label-secondary btn-sm secondary-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>
|
||||
</div>
|
||||
<hr class="mt-2" />
|
||||
</div>
|
||||
<div class="col-md-12 mb-3">
|
||||
<label class="form-label">Title <span class="text-danger">*</span></label>
|
||||
<input type="text" class="form-control" name="name"
|
||||
value="{{ old('name', $transformation->name ?? '') }}" placeholder="e.g. John Doe" />
|
||||
@error('name')
|
||||
<div class="text-danger">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label">Hair Loss Grade</label>
|
||||
<input type="text" class="form-control" name="grade"
|
||||
value="{{ old('grade', $transformation->grade ?? '') }}" placeholder="e.g. 03" />
|
||||
@error('grade')
|
||||
<div class="text-danger">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="col-md-6 mb-3">
|
||||
<label class="form-label">Number of Grafts</label>
|
||||
<input type="text" class="form-control" name="graft"
|
||||
value="{{ old('graft', $transformation->graft ?? '') }}" placeholder="e.g. 2,500" />
|
||||
@error('graft')
|
||||
<div class="text-danger">{{ $message }}</div>
|
||||
@enderror
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<button type="submit" class="btn btn-primary">
|
||||
@if (empty($transformation))
|
||||
Save
|
||||
@else
|
||||
Save Changes
|
||||
@endif
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@push('required-scripts')
|
||||
@include('admin::vendor.select2.script')
|
||||
@include('admin::vendor.tinymce.script')
|
||||
@endpush
|
0
Modules/Transformation/routes/.gitkeep
Normal file
0
Modules/Transformation/routes/.gitkeep
Normal file
19
Modules/Transformation/routes/api.php
Normal file
19
Modules/Transformation/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('transformation', fn (Request $request) => $request->user())->name('transformation');
|
||||
});
|
24
Modules/Transformation/routes/web.php
Normal file
24
Modules/Transformation/routes/web.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Route;
|
||||
use Modules\Transformation\app\Http\Controllers\TransformationController;
|
||||
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| 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']], function () {
|
||||
Route::get('transformations', [TransformationController::class, 'index'])->name('transformation.index');
|
||||
Route::get('transformations/create', [TransformationController::class, 'create'])->name('transformation.create');
|
||||
Route::post('transformations/store', [TransformationController::class, 'store'])->name('transformation.store');
|
||||
Route::get('transformations/{id}/edit', [TransformationController::class, 'edit'])->name('transformation.edit');
|
||||
Route::put('transformations/{id}/update', [TransformationController::class, 'update'])->name('transformation.update');
|
||||
Route::delete('transformations/{id}/delete', [TransformationController::class, 'destroy'])->name('transformation.delete');
|
||||
});
|
0
Modules/Transformation/tests/Feature/.gitkeep
Normal file
0
Modules/Transformation/tests/Feature/.gitkeep
Normal file
0
Modules/Transformation/tests/Unit/.gitkeep
Normal file
0
Modules/Transformation/tests/Unit/.gitkeep
Normal file
26
Modules/Transformation/vite.config.js
Normal file
26
Modules/Transformation/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-transformation',
|
||||
emptyOutDir: true,
|
||||
manifest: true,
|
||||
},
|
||||
plugins: [
|
||||
laravel({
|
||||
publicDirectory: '../../public',
|
||||
buildDirectory: 'build-transformation',
|
||||
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