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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user