Viewing file: TemplateController.php (9.27 KB) -rw-r--r-- Select action/file-type: (+) | (+) | (+) | Code (+) | Session (+) | (+) | SDB (+) | (+) | (+) | (+) | (+) | (+) |
<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use App\Models\Settings;
use Illuminate\Http\Request;
class TemplateController extends Controller
{
public function index(){
return view('admin.front_template.index');
}
public function store(Request $request){
if (config("app.demo")){
return redirect()->back()->withErrors(['message' => trans('admin.app_demo_message')]);
}
$aboutSection = json_decode(get_settings('about_section'));
$featuresSection = json_decode(get_settings('features_section'));
$groupListBuilderSection = json_decode(get_settings('group_list_builder_section'));
$customerManagementSection = json_decode(get_settings('customer_management_section'));
$billingManagementSection = json_decode(get_settings('billing_management_section'));
$formAndEmailTemplateBuilderSection = json_decode(get_settings('form_and_email_template_builder_section'));
$planManagementSection = json_decode(get_settings('plan_management_section'));
$popularPaymentGatewaySection = json_decode(get_settings('popular_payment_gateway_section'));
if ($request->name == 'home_section'){
$data = ['name' => 'home_section'];
$setting = auth()->user()->settings()->firstOrNew($data);
$setting->value = json_encode($request->only('home_section_heading','home_section_title'));
$setting->save();
}
if ($request->name == 'about_section') {
if ($request->hasFile('about_section_image')) {
$file = $request->file('about_section_image');
$imageName = time() . '_1' . '.' . $file->getClientOriginalExtension();
$file->move(public_path('/uploads'), $imageName);
$request['about_section_img'] = $imageName;
} else {
$request['about_section_img'] = isset($aboutSection)?$aboutSection->about_section_img:'';
}
$data = ['name' => 'about_section'];
$setting = auth()->user()->settings()->firstOrNew($data);
$setting->value = json_encode($request->only('about_section_title', 'about_section_description', 'about_section_img'));
$setting->save();
}
if ($request->name == 'features_section') {
if ($request->hasFile('features_section_image')) {
$file = $request->file('features_section_image');
$imageOneName = time(). '_2'. '.' . $file->getClientOriginalExtension();
$file->move(public_path('/uploads'), $imageOneName);
$request['features_section_img'] = $imageOneName;
} else {
$request['features_section_img'] = isset($featuresSection)?$featuresSection->features_section_img:'';
}
$data = ['name' => 'features_section'];
$setting = auth()->user()->settings()->firstOrNew($data);
$setting->value = json_encode($request->only('features_section_title', 'features_section_description', 'features_section_img'));
$setting->save();
}
if ($request->name == 'group_list_builder_section') {
if ($request->hasFile('group_list_builder_section_image')) {
$file = $request->file('group_list_builder_section_image');
$imageTwoName = time(). '_3' . '.' . $file->getClientOriginalExtension();
$file->move(public_path('/uploads'), $imageTwoName);
$request['group_list_builder_section_img'] = $imageTwoName;
} else {
$request['group_list_builder_section_img'] = isset($groupListBuilderSection)?$groupListBuilderSection->group_list_builder_section_img:'';
}
$data = ['name' => 'group_list_builder_section'];
$setting = auth()->user()->settings()->firstOrNew($data);
$setting->value = json_encode($request->only('group_list_builder_section_title', 'group_list_builder_section_description', 'group_list_builder_section_img'));
$setting->save();
}
if ($request->name == 'customer_management_section') {
if ($request->hasFile('customer_management_section_image')) {
$file = $request->file('customer_management_section_image');
$imageThreeName = time(). '_4' . '.' . $file->getClientOriginalExtension();
$file->move(public_path('/uploads'), $imageThreeName);
$request['customer_management_section_img'] = $imageThreeName;
} else {
$request['customer_management_section_img'] = isset($customerManagementSection)?$customerManagementSection->customer_management_section_img:'';
}
$data = ['name' => 'customer_management_section'];
$setting = auth()->user()->settings()->firstOrNew($data);
$setting->value = json_encode($request->only('customer_management_section_title', 'customer_management_section_description', 'customer_management_section_img'));
$setting->save();
}
if ($request->name == 'billing_management_section') {
if ($request->hasFile('billing_management_section_image')) {
$file = $request->file('billing_management_section_image');
$imagefourName = time(). '_5' . '.' . $file->getClientOriginalExtension();
$file->move(public_path('/uploads'), $imagefourName);
$request['billing_management_section_img'] = $imagefourName;
} else {
$request['billing_management_section_img'] = isset($billingManagementSection)?$billingManagementSection->billing_management_section_img:'';
}
$data = ['name' => 'billing_management_section'];
$setting = auth()->user()->settings()->firstOrNew($data);
$setting->value = json_encode($request->only('billing_management_section_title', 'billing_management_section_description', 'billing_management_section_img'));
$setting->save();
}
if ($request->name == 'form_and_email_template_builder_section') {
if ($request->hasFile('form_and_email_template_builder_section_image')) {
$file = $request->file('form_and_email_template_builder_section_image');
$imagefourName = time(). '_5' . '.' . $file->getClientOriginalExtension();
$file->move(public_path('/uploads'), $imagefourName);
$request['form_and_email_template_builder_section_img'] = $imagefourName;
} else {
$request['form_and_email_template_builder_section_img'] = isset($formAndEmailTemplateBuilderSection)?$formAndEmailTemplateBuilderSection->form_and_email_template_builder_section_img:'';
}
$data = ['name' => 'form_and_email_template_builder_section'];
$setting = auth()->user()->settings()->firstOrNew($data);
$setting->value = json_encode($request->only('form_and_email_template_builder_section_title', 'form_and_email_template_builder_section_description', 'form_and_email_template_builder_section_img'));
$setting->save();
}
if ($request->name == 'plan_management_section') {
if ($request->hasFile('plan_management_section_image')) {
$file = $request->file('plan_management_section_image');
$imageSixName = time(). '_7' . '.' . $file->getClientOriginalExtension();
$file->move(public_path('/uploads'), $imageSixName);
$request['plan_management_section_img'] = $imageSixName;
}else {
$request['plan_management_section_img'] = isset($planManagementSection)?$planManagementSection->plan_management_section_img:'';
}
$data = ['name' => 'plan_management_section'];
$setting = auth()->user()->settings()->firstOrNew($data);
$setting->value = json_encode($request->only('plan_management_section_title', 'plan_management_section_description', 'plan_management_section_img'));
$setting->save();
}
if ($request->name == 'popular_payment_gateway_section') {
if ($request->hasFile('popular_payment_gateway_section_image')) {
$file = $request->file('popular_payment_gateway_section_image');
$imageSevenName = time(). '_8' . '.' . $file->getClientOriginalExtension();
$file->move(public_path('/uploads'), $imageSevenName);
$request['popular_payment_gateway_section_img'] = $imageSevenName;
}else {
$request['popular_payment_gateway_section_img'] = isset($popularPaymentGatewaySection)?$popularPaymentGatewaySection->popular_payment_gateway_section_img:'';
}
$data = ['name' => 'popular_payment_gateway_section'];
$setting = auth()->user()->settings()->firstOrNew($data);
$setting->value = json_encode($request->only('popular_payment_gateway_section_title', 'popular_payment_gateway_description', 'popular_payment_gateway_section_img'));
$setting->save();
}
cache()->flush();
return redirect()->back()->with('success','Template successfully update');
}
}
|