firstcommit
This commit is contained in:
0
Modules/TeamMember/app/Http/Controllers/.gitkeep
Normal file
0
Modules/TeamMember/app/Http/Controllers/.gitkeep
Normal file
137
Modules/TeamMember/app/Http/Controllers/TeamMemberController.php
Normal file
137
Modules/TeamMember/app/Http/Controllers/TeamMemberController.php
Normal file
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\TeamMember\app\Http\Controllers;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Modules\TeamMember\app\Models\TeamMember;
|
||||
use Modules\TeamMember\app\Models\SocialShare;
|
||||
use Modules\TeamMember\app\Services\FileManagementService;
|
||||
use Modules\TeamMember\app\Repositories\TeamMemberRepository;
|
||||
use Modules\TeamMember\app\Http\Requests\CreateTeamMemberRequest;
|
||||
use Modules\TeamMember\app\Http\Requests\CreateSocialShareRequest;
|
||||
|
||||
class TeamMemberController extends Controller
|
||||
{
|
||||
|
||||
protected $teamMemberRepository;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->teamMemberRepository = new TeamMemberRepository;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 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') : [];
|
||||
$team_members = $this->teamMemberRepository->allTeamMember($perPage, $filter);
|
||||
return view('teammember::index', compact('team_members'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return view('teammember::create');
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
|
||||
public function store(CreateTeamMemberRequest $request): RedirectResponse
|
||||
{
|
||||
|
||||
try {
|
||||
$validated = $request->validated();
|
||||
|
||||
$this->teamMemberRepository->storeTeamMember($validated);
|
||||
|
||||
toastr()->success('Team Member created successfully.');
|
||||
|
||||
return redirect()->route('cms.team-members.index');
|
||||
} catch (\Throwable $th) {
|
||||
report($th);
|
||||
toastr()->error('Something went wrong.');
|
||||
return back();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
return view('teammember::show');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit($uuid)
|
||||
{
|
||||
$team_member = $this->teamMemberRepository->findTeamMemberByUuid($uuid);
|
||||
if (!$team_member) {
|
||||
toastr()->error('Team Member not found.');
|
||||
return back();
|
||||
} return view('teammember::edit',compact('team_member'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(CreateTeamMemberRequest $request, $uuid): RedirectResponse
|
||||
{
|
||||
$validated = $request->validated();
|
||||
try {
|
||||
$team_member = $this->teamMemberRepository->updateTeamMember($validated, $uuid);
|
||||
|
||||
if (!$team_member) {
|
||||
toastr()->error('Team Member not found !');
|
||||
return back();
|
||||
}
|
||||
|
||||
toastr()->success('Team Member updated successfully.');
|
||||
|
||||
return redirect()->route('cms.team-members.index');
|
||||
} catch (\Throwable $th) {
|
||||
report($th);
|
||||
toastr()->error('Something went wrong.');
|
||||
return back();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy($uuid)
|
||||
{
|
||||
try {
|
||||
$team_member = $this->teamMemberRepository->deleteTeamMember($uuid);
|
||||
|
||||
if (!$team_member) {
|
||||
toastr()->error('Team Member not found.');
|
||||
return back();
|
||||
}
|
||||
|
||||
toastr()->success('Team Member deleted successfully.');
|
||||
|
||||
return redirect()->route('cms.team-members.index');
|
||||
} catch (\Throwable $th) {
|
||||
report($th);
|
||||
toastr()->error('Something went wrong.');
|
||||
return back();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
0
Modules/TeamMember/app/Http/Middleware/.gitkeep
Normal file
0
Modules/TeamMember/app/Http/Middleware/.gitkeep
Normal file
0
Modules/TeamMember/app/Http/Requests/.gitkeep
Normal file
0
Modules/TeamMember/app/Http/Requests/.gitkeep
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\TeamMember\app\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class CreateSocialShareRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
// 'name' => 'required|string|max:255',
|
||||
// 'link' => 'required|string|max:255',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\TeamMember\app\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class CreateTeamMemberRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'name' => 'required|string|max:255|regex:/^[a-zA-Z. ]+$/',
|
||||
'group_id' => 'required|integer|min:1',
|
||||
'designation' => 'required|string|max:255',
|
||||
'detail' => 'sometimes|nullable|string',
|
||||
// 'group-a' => 'array',
|
||||
'image' => 'sometimes|nullable|image|mimes:jpeg,png,jpg,gif',
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'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.',
|
||||
|
||||
'group_id.required' => 'The group ID field is required.',
|
||||
'group_id.integer' => 'The group ID must be an integer.',
|
||||
'group_id.min' => 'The group ID must be at least 1.',
|
||||
|
||||
'designation.required' => 'The designation field is required.',
|
||||
'designation.string' => 'The designation field must be a string.',
|
||||
'designation.max' => 'The designation may not be greater than 255 characters.',
|
||||
|
||||
'detail.string' => 'The detail field must be a string.',
|
||||
|
||||
'image.image' => 'The image must be an image file.',
|
||||
'image.mimes' => 'The image must be a file of type: jpeg, png, jpg, gif.',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\TeamMember\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.');
|
||||
}
|
||||
}
|
||||
}
|
0
Modules/TeamMember/app/Models/.gitkeep
Normal file
0
Modules/TeamMember/app/Models/.gitkeep
Normal file
31
Modules/TeamMember/app/Models/SocialShare.php
Normal file
31
Modules/TeamMember/app/Models/SocialShare.php
Normal file
@@ -0,0 +1,31 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\TeamMember\app\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Modules\TeamMember\Database\factories\SocialShareFactory;
|
||||
|
||||
class SocialShare extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected $fillable = [
|
||||
// 'uuid',
|
||||
// 'team_member_id',
|
||||
// 'name',
|
||||
// 'link',
|
||||
];
|
||||
|
||||
// public function teamMember(){
|
||||
// return $this->belongsTo(TeamMember::class, 'team_member_id');
|
||||
// }
|
||||
|
||||
protected static function newFactory(): SocialShareFactory
|
||||
{
|
||||
//return SocialShareFactory::new();
|
||||
}
|
||||
}
|
42
Modules/TeamMember/app/Models/TeamMember.php
Normal file
42
Modules/TeamMember/app/Models/TeamMember.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\TeamMember\app\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Modules\TeamMember\Database\factories\TeamMemberFactory;
|
||||
|
||||
class TeamMember extends Model
|
||||
{
|
||||
const FILE_PATH = 'uploads/teamMembers/';
|
||||
|
||||
use HasFactory;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected $fillable = [
|
||||
'uuid',
|
||||
'name',
|
||||
'group_id',
|
||||
'designation',
|
||||
'detail',
|
||||
'image',
|
||||
'image_path',
|
||||
];
|
||||
|
||||
// public function socialShares()
|
||||
// {
|
||||
// return $this->hasMany(SocialShare::class, 'team_member_id');
|
||||
// }
|
||||
|
||||
protected static function newFactory(): TeamMemberFactory
|
||||
{
|
||||
//return TeamMemberFactory::new();
|
||||
}
|
||||
|
||||
public function getFullImageAttribute()
|
||||
{
|
||||
return $this->image ? asset('storage/' . Self::FILE_PATH . $this->image) : null;
|
||||
}
|
||||
}
|
0
Modules/TeamMember/app/Providers/.gitkeep
Normal file
0
Modules/TeamMember/app/Providers/.gitkeep
Normal file
59
Modules/TeamMember/app/Providers/RouteServiceProvider.php
Normal file
59
Modules/TeamMember/app/Providers/RouteServiceProvider.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\TeamMember\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\TeamMember\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('TeamMember', '/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('TeamMember', '/routes/api.php'));
|
||||
}
|
||||
}
|
114
Modules/TeamMember/app/Providers/TeamMemberServiceProvider.php
Normal file
114
Modules/TeamMember/app/Providers/TeamMemberServiceProvider.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\TeamMember\app\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class TeamMemberServiceProvider extends ServiceProvider
|
||||
{
|
||||
protected string $moduleName = 'TeamMember';
|
||||
|
||||
protected string $moduleNameLower = 'teammember';
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
144
Modules/TeamMember/app/Repositories/TeamMemberRepository.php
Normal file
144
Modules/TeamMember/app/Repositories/TeamMemberRepository.php
Normal file
@@ -0,0 +1,144 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\TeamMember\app\Repositories;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Modules\TeamMember\app\Models\TeamMember;
|
||||
use Modules\TeamMember\app\Models\SocialShare;
|
||||
use Modules\Banner\app\Services\FileManagementService;
|
||||
|
||||
class TeamMemberRepository
|
||||
{
|
||||
|
||||
//-- Retrieve all Services
|
||||
public function allTeamMember($perPage = null, $filter = [], $sort = ['by' => 'id', 'sort' => 'DESC'])
|
||||
{
|
||||
return TeamMember::when(array_keys($filter, true), function ($query) use ($filter) {
|
||||
if (!empty($filter['name'])) {
|
||||
$query->where('name', $filter['name']);
|
||||
}
|
||||
if (!empty($filter['designation'])) {
|
||||
$query->where('designation', 'like', '%' . $filter['designation'] . '%');
|
||||
}
|
||||
})
|
||||
->orderBy($sort['by'], $sort['sort'])
|
||||
->paginate($perPage ?: env('PAGE_LIMIT', 999));
|
||||
}
|
||||
|
||||
//-- Find Service by uuid
|
||||
public function findTeamMemberByUuid($uuid)
|
||||
{
|
||||
return TeamMember::where('uuid', $uuid)->first();
|
||||
}
|
||||
|
||||
public function storeTeamMember(array $validated)
|
||||
{
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
$teamMember = new TeamMember();
|
||||
$teamMember->uuid = Str::uuid();
|
||||
$teamMember->name = $validated['name'];
|
||||
if ($validated['group_id'] < 4 & $validated['group_id'] > 0) {
|
||||
$teamMember->group_id = $validated['group_id'];
|
||||
}
|
||||
$teamMember->designation = $validated['designation'];
|
||||
$teamMember->detail = $validated['detail'];
|
||||
$teamMember->save();
|
||||
|
||||
|
||||
// social media team member
|
||||
// if (isset($validated['group-a']) && is_array($validated['group-a'])) {
|
||||
// foreach ($validated['group-a'] as $socialShareData) {
|
||||
// $socialShare = new SocialShare([
|
||||
// 'uuid' => Str::uuid(),
|
||||
// 'name' => $socialShareData['name'],
|
||||
// 'link' => $socialShareData['link'],
|
||||
// ]);
|
||||
// $teamMember->socialShares()->save($socialShare);
|
||||
// }
|
||||
// }
|
||||
|
||||
if (isset($validated['image']) && $validated['image']->isValid()) {
|
||||
FileManagementService::uploadFile(
|
||||
file: $validated['image'],
|
||||
uploadedFolderName: 'teamMembers',
|
||||
filePath: $teamMember->image_path,
|
||||
model: $teamMember
|
||||
);
|
||||
}
|
||||
|
||||
DB::commit();
|
||||
|
||||
return $teamMember;
|
||||
} catch (\Throwable $th) {
|
||||
report($th);
|
||||
DB::rollback();
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public function updateTeamMember($validated, $uuid)
|
||||
{
|
||||
try {
|
||||
$teamMember = $this->findTeamMemberByUuid($uuid);
|
||||
if (!$teamMember) {
|
||||
|
||||
return null;
|
||||
}
|
||||
$teamMember->name = $validated['name'];
|
||||
if ($validated['group_id'] < 4 & $validated['group_id'] > 0) {
|
||||
$teamMember->group_id = $validated['group_id'];
|
||||
}
|
||||
$teamMember->designation = $validated['designation'];
|
||||
$teamMember->detail = $validated['detail'];
|
||||
$teamMember->save();
|
||||
|
||||
if (isset($validated['image']) && $validated['image']->isValid()) {
|
||||
FileManagementService::uploadFile(
|
||||
file: $validated['image'],
|
||||
uploadedFolderName: 'teamMembers',
|
||||
filePath: $teamMember->image_path,
|
||||
model: $teamMember
|
||||
);
|
||||
}
|
||||
|
||||
return $teamMember;
|
||||
DB::commit();
|
||||
} catch (\Throwable $th) {
|
||||
report($th);
|
||||
DB::rollBack();
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
//-- Delete Testimonial
|
||||
public function deleteTeamMember(string $uuid)
|
||||
{
|
||||
DB::beginTransaction();
|
||||
try {
|
||||
$teamMember = $this->findTeamMemberByUuid($uuid);
|
||||
if (!$teamMember) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// Delete the image file associated with the activity
|
||||
if ($teamMember->image_path !== null) {
|
||||
FileManagementService::deleteFile($teamMember->image_path);
|
||||
}
|
||||
|
||||
$teamMember->delete();
|
||||
|
||||
DB::commit();
|
||||
|
||||
return $teamMember;
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollBack();
|
||||
report($th);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
66
Modules/TeamMember/app/Services/FileManagementService.php
Normal file
66
Modules/TeamMember/app/Services/FileManagementService.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\TeamMember\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.');
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user