firstcommit
This commit is contained in:
0
Modules/Setting/app/Http/Controllers/.gitkeep
Normal file
0
Modules/Setting/app/Http/Controllers/.gitkeep
Normal file
207
Modules/Setting/app/Http/Controllers/SettingController.php
Normal file
207
Modules/Setting/app/Http/Controllers/SettingController.php
Normal file
@@ -0,0 +1,207 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Setting\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 Illuminate\Support\Facades\Session;
|
||||
use Modules\Setting\app\Models\Setting;
|
||||
use Modules\Setting\app\Models\SettingImage;
|
||||
use Modules\Setting\Repositories\SettingDaoImpl;
|
||||
use Modules\Setting\app\Services\FileManagementService;
|
||||
use Modules\Setting\app\Http\Requests\CreateSettingRequest;
|
||||
use Modules\Setting\app\Http\Requests\UpdateSettingRequest;
|
||||
use Modules\Setting\app\Http\Requests\CreateOrUpdateSettingRequest;
|
||||
use Modules\Setting\app\Http\Requests\CreateOrUpdateSeoSettingRequest;
|
||||
use Modules\Setting\app\Http\Requests\CreateOrUpdateGeneralSettingRequest;
|
||||
use Modules\Setting\app\Http\Requests\CreateOrUpdateAdditionalSettingRequest;
|
||||
use Modules\Setting\app\Http\Requests\CreateOrUpdateConnectionSettingRequest;
|
||||
|
||||
class SettingController extends Controller
|
||||
{
|
||||
//-- Get all the settings
|
||||
public function index()
|
||||
{
|
||||
try {
|
||||
$data['generalSettings'] = Setting::where('setting_name', 'general_setting')
|
||||
->pluck('detail', 'name')
|
||||
->all();
|
||||
$data['settingImage'] = Setting::where('setting_name', 'setting_image')
|
||||
->pluck('detail', 'name')
|
||||
->all();
|
||||
$data['socialShares'] = Setting::where('setting_name', 'social_setting')->get();
|
||||
$data['seoSettings'] = Setting::where('setting_name', 'seo_setting')->pluck('detail', 'name')->all();
|
||||
$data['additionalSettings'] = Setting::where('setting_name', 'additional_setting')->pluck('detail', 'name')->all();
|
||||
|
||||
return view('setting::create', $data);
|
||||
} catch (\Throwable $th) {
|
||||
throw $th;
|
||||
report($th);
|
||||
toastr()->error('Oops! Something went wrong.');
|
||||
return back();
|
||||
}
|
||||
}
|
||||
|
||||
//-- Create or Update general setting
|
||||
public function generalStoreOrUpdate(CreateOrUpdateGeneralSettingRequest $request)
|
||||
{
|
||||
try {
|
||||
$validated = $request->validated();
|
||||
|
||||
// Check if general setting already exists
|
||||
$generalSetting = Setting::where('setting_name', 'general_setting')->first();
|
||||
|
||||
if ($generalSetting) {
|
||||
// Update existing general settings
|
||||
foreach ($validated as $key => $generalSettingItem) {
|
||||
$generalSettingContent = Setting::where('setting_name', 'general_setting')->where('name', $key)->first();
|
||||
|
||||
if ($generalSettingContent && !is_null($generalSettingContent)) {
|
||||
// Check if the file exists in the request and matches the current $generalSettingItem
|
||||
if ($request->hasFile($key)) {
|
||||
FileManagementService::uploadFile(
|
||||
file: $request->file($key),
|
||||
uploadedFolderName: 'settings',
|
||||
filePath: $generalSettingContent->detail,
|
||||
model: $generalSettingContent
|
||||
);
|
||||
} else {
|
||||
$generalSettingContent->detail = $generalSettingItem;
|
||||
$generalSettingContent->save();
|
||||
}
|
||||
} else {
|
||||
$newGeneralSetting = new Setting();
|
||||
$newGeneralSetting->uuid = Str::uuid();
|
||||
$newGeneralSetting->setting_name = 'general_setting';
|
||||
$newGeneralSetting->name = $key;
|
||||
if ($request->hasFile($key)) {
|
||||
FileManagementService::storeFile(
|
||||
file: $request->file($key),
|
||||
uploadedFolderName: 'settings',
|
||||
model: $newGeneralSetting
|
||||
);
|
||||
} else {
|
||||
$newGeneralSetting->detail = $generalSettingItem;
|
||||
$newGeneralSetting->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Create new general settings data
|
||||
foreach ($validated as $key => $generalSettingItem) {
|
||||
$newGeneralSetting = new Setting();
|
||||
$newGeneralSetting->uuid = Str::uuid();
|
||||
$newGeneralSetting->setting_name = 'general_setting';
|
||||
$newGeneralSetting->name = $key;
|
||||
if ($request->hasFile($key)) {
|
||||
FileManagementService::storeFile(
|
||||
file: $request->file($key),
|
||||
uploadedFolderName: 'settings',
|
||||
model: $newGeneralSetting
|
||||
);
|
||||
} else {
|
||||
$newGeneralSetting->detail = $generalSettingItem;
|
||||
$newGeneralSetting->save();
|
||||
}
|
||||
}
|
||||
}
|
||||
$message = $generalSetting ? "General Setting updated successfully." : "General Setting created successfully.";
|
||||
toastr()->success($message);
|
||||
|
||||
return redirect()->route('setting.index');
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollback();
|
||||
report($th);
|
||||
toastr()->error('Something went wrong.');
|
||||
return back();
|
||||
}
|
||||
}
|
||||
|
||||
//-- Create or Update connection setting
|
||||
public function connectionStoreOrUpdate(Request $request)
|
||||
{
|
||||
try {
|
||||
foreach ($request->socialShares as $socialshare) {
|
||||
if (!empty($socialshare['social_site'])) {
|
||||
Setting::updateOrCreate(
|
||||
['name' => $socialshare['social_site']],
|
||||
[
|
||||
'uuid' => Str::uuid(),
|
||||
'setting_name' => 'social_setting',
|
||||
'name' => $socialshare['social_site'],
|
||||
'detail' => $socialshare['social_link'],
|
||||
]
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
toastr()->success('Connection Setting created successfully.');
|
||||
|
||||
return redirect()->route('setting.index');
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollback();
|
||||
report($th);
|
||||
toastr()->error('Something went wrong.');
|
||||
return back();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//-- Create or Update seo setting
|
||||
public function seoStoreOrUpdate(CreateOrUpdateSeoSettingRequest $request)
|
||||
{
|
||||
try {
|
||||
$validated = $request->validated();
|
||||
foreach ($validated as $key => $seoSetting) {
|
||||
Setting::updateOrCreate(
|
||||
['name' => $key],
|
||||
[
|
||||
'uuid' => Str::uuid(),
|
||||
'setting_name' => 'seo_setting',
|
||||
'name' => $key,
|
||||
'detail' => $seoSetting,
|
||||
]
|
||||
);
|
||||
}
|
||||
|
||||
toastr()->success('SEO Setting created successfully.');
|
||||
|
||||
return redirect()->route('setting.index');
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollback();
|
||||
report($th);
|
||||
toastr()->error('Something went wrong.');
|
||||
return back();
|
||||
}
|
||||
}
|
||||
|
||||
public function additionalStoreOrUpdate(CreateOrUpdateAdditionalSettingRequest $request)
|
||||
{
|
||||
try {
|
||||
$validated = $request->validated();
|
||||
foreach ($validated as $key => $additonalSetting) {
|
||||
Setting::updateOrCreate(
|
||||
['name' => $key],
|
||||
[
|
||||
'uuid' => Str::uuid(),
|
||||
'setting_name' => 'additional_setting',
|
||||
'name' => $key,
|
||||
'detail' => $additonalSetting,
|
||||
]
|
||||
);
|
||||
}
|
||||
toastr()->success('Additional Settings updated successfully.');
|
||||
|
||||
return redirect()->route('setting.index');
|
||||
} catch (\Throwable $th) {
|
||||
DB::rollback();
|
||||
report($th);
|
||||
toastr()->error('Something went wrong.');
|
||||
return back();
|
||||
}
|
||||
}
|
||||
}
|
0
Modules/Setting/app/Http/Middleware/.gitkeep
Normal file
0
Modules/Setting/app/Http/Middleware/.gitkeep
Normal file
0
Modules/Setting/app/Http/Requests/.gitkeep
Normal file
0
Modules/Setting/app/Http/Requests/.gitkeep
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Setting\app\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class CreateOrUpdateAdditionalSettingRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'additional_script' => 'nullable|string',
|
||||
'map' => 'nullable|string',
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'additional_script.string' => 'The additional script field must be a string.',
|
||||
'map.string' => 'The map field must be a string.',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Setting\app\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class CreateOrUpdateConnectionSettingRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -0,0 +1,77 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Setting\app\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Support\Arr;
|
||||
|
||||
class CreateOrUpdateGeneralSettingRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'primary_image' => 'nullable|image|mimes:jpeg,png,jpg,gif|max:3072',
|
||||
'secondary_image' => 'nullable|image|mimes:jpeg,png,jpg,gif|max:3072',
|
||||
'company_name' => 'required|string|max:255',
|
||||
'address' => 'nullable|string|max:255',
|
||||
'contact_number' => 'nullable|string|max:255',
|
||||
'info_email_address' => 'nullable|email|max:255',
|
||||
'mobile_number' => 'nullable|string|max:255',
|
||||
'alt_mobile_number' => 'nullable|string|max:255',
|
||||
'support_email_address' => 'nullable|email|max:255',
|
||||
'opening_hours' => 'nullable|string|max:255',
|
||||
'short_detail' => 'nullable|string',
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'primary_image.image' => 'The primary image must be an image file.',
|
||||
'primary_image.mimes' => 'The primary image must be a file of type: jpeg, png, jpg, gif.',
|
||||
'primary_image.max' => 'The primary image may not be greater than 3MB.',
|
||||
|
||||
'secondary_image.image' => 'The secondary image must be an image file.',
|
||||
'secondary_image.mimes' => 'The secondary image must be a file of type: jpeg, png, jpg, gif.',
|
||||
'secondary_image.max' => 'The secondary image may not be greater than 3MB.',
|
||||
|
||||
'company_name.required' => 'The company name field is required.',
|
||||
'company_name.string' => 'The company name field must be a string.',
|
||||
'company_name.max' => 'The company name may not be greater than 255 characters.',
|
||||
|
||||
'address.string' => 'The address field must be a string.',
|
||||
'address.max' => 'The address may not be greater than 255 characters.',
|
||||
|
||||
'contact_number.string' => 'The contact number field must be a string.',
|
||||
'contact_number.max' => 'The contact number may not be greater than 255 characters.',
|
||||
|
||||
'info_email_address.email' => 'The info email address must be a valid email address.',
|
||||
'info_email_address.max' => 'The info email address may not be greater than 255 characters.',
|
||||
|
||||
'mobile_number.string' => 'The mobile number field must be a string.',
|
||||
'mobile_number.max' => 'The mobile number may not be greater than 255 characters.',
|
||||
|
||||
'alt_mobile_number.string' => 'The alt mobile number field must be a string.',
|
||||
'alt_mobile_number.max' => 'The alt mobile number may not be greater than 255 characters.',
|
||||
|
||||
'support_email_address.email' => 'The support email address must be a valid email address.',
|
||||
'support_email_address.max' => 'The support email address may not be greater than 255 characters.',
|
||||
|
||||
'opening_hours.string' => 'The opening hours field must be a string.',
|
||||
'opening_hours.max' => 'The opening hours may not be greater than 255 characters.',
|
||||
|
||||
'short_detail.string' => 'The short detail field must be a string.',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Setting\app\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class CreateOrUpdateSeoSettingRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'meta_keywords' => 'sometimes|nullable|string|max:255',
|
||||
'meta_detail' => 'sometimes|nullable|string|max:255',
|
||||
'meta_title' => 'sometimes|nullable|string|max:255',
|
||||
];
|
||||
}
|
||||
|
||||
public function messages()
|
||||
{
|
||||
return [
|
||||
'meta_keywords.string' => 'The meta keywords field must be a string.',
|
||||
'meta_keywords.max' => 'The meta keywords may not be greater than 255 characters.',
|
||||
|
||||
'meta_detail.string' => 'The meta detail field must be a string.',
|
||||
'meta_detail.max' => 'The meta detail may not be greater than 255 characters.',
|
||||
|
||||
'meta_title.string' => 'The meta title field must be a string.',
|
||||
'meta_title.max' => 'The meta title may not be greater than 255 characters.',
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
0
Modules/Setting/app/Models/.gitkeep
Normal file
0
Modules/Setting/app/Models/.gitkeep
Normal file
34
Modules/Setting/app/Models/Setting.php
Normal file
34
Modules/Setting/app/Models/Setting.php
Normal file
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Setting\app\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Modules\Setting\Database\factories\SettingFactory;
|
||||
|
||||
class Setting extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*/
|
||||
protected $fillable = [
|
||||
'uuid',
|
||||
'setting_name',
|
||||
'name',
|
||||
'detail',
|
||||
'status',
|
||||
|
||||
];
|
||||
|
||||
// protected static function newFactory(): SettingFactory
|
||||
// {
|
||||
// //return SettingFactory::new();
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* Function to get full image path
|
||||
*/
|
||||
|
||||
}
|
0
Modules/Setting/app/Providers/.gitkeep
Normal file
0
Modules/Setting/app/Providers/.gitkeep
Normal file
59
Modules/Setting/app/Providers/RouteServiceProvider.php
Normal file
59
Modules/Setting/app/Providers/RouteServiceProvider.php
Normal file
@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Setting\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\Setting\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('Setting', '/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('Setting', '/routes/api.php'));
|
||||
}
|
||||
}
|
114
Modules/Setting/app/Providers/SettingServiceProvider.php
Normal file
114
Modules/Setting/app/Providers/SettingServiceProvider.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Setting\app\Providers;
|
||||
|
||||
use Illuminate\Support\Facades\Blade;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class SettingServiceProvider extends ServiceProvider
|
||||
{
|
||||
protected string $moduleName = 'Setting';
|
||||
|
||||
protected string $moduleNameLower = 'setting';
|
||||
|
||||
/**
|
||||
* 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;
|
||||
}
|
||||
}
|
69
Modules/Setting/app/Services/FileManagementService.php
Normal file
69
Modules/Setting/app/Services/FileManagementService.php
Normal file
@@ -0,0 +1,69 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Setting\app\Services;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
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->detail = $uploadedFolderName . '/' . $modifiedFileName;
|
||||
$model->save();
|
||||
} catch (\Throwable $th) {
|
||||
report($th);
|
||||
toastr()->error('Something went wrong in image.');
|
||||
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->uuid = Str::uuid();
|
||||
// $model->setting_name = 'setting_image';
|
||||
// $model->name = $modifiedFileName;
|
||||
$model->detail = $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