Server : Apache System : Linux host44.registrar-servers.com 4.18.0-513.18.1.lve.2.el8.x86_64 #1 SMP Sat Mar 30 15:36:11 UTC 2024 x86_64 User : vapecompany ( 2719) PHP Version : 7.4.33 Disable Function : NONE Directory : /proc/thread-self/root/home/vapecompany/demo.vapecompany.com.bd/app/Http/Controllers/Backend/ |
Upload File : |
<?php namespace App\Http\Controllers\Backend; use App\Http\Controllers\Controller; use App\Models\CompanyInfo; use Illuminate\Http\Request; //use Response; //use Illuminate\Http\Response; use Illuminate\Support\Facades\Artisan; use Carbon\Carbon; use Illuminate\Support\Facades\Storage; class CompanyInfoController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function __construct() { $this->middleware('admin'); } public function get_db_backup() { // if(!auth()->user()->canEvent('db_backup')) // { // return redirect('/'); // } return view('backend.db_back_up'); } public function post_db_backup(){ $dir=base_path("app/bakup"); //$FolderToDelete = base_path('path_to_your_directory'); $fs = new \Illuminate\Filesystem\Filesystem; $fs->cleanDirectory($dir); // $files = Storage::allFiles($dir); // return $files; // // Delete Files // Storage::delete($files); try { Artisan::call('database:backup'); } catch(\Exception $e) { return response()->json([ 'success' => false, 'errors' => "" ], 400); } $file_name="backup-" . Carbon::now()->format('d-m-Y') . ".sql"; $file_path = base_path() . "/app/backup/" . $file_name; return response()->download($file_path); } public function index() { // if(!auth()->user()->canEvent('setting')) // { // return redirect('/'); // } $companyInfo= CompanyInfo::first(); //dd( $companyInfo); if($companyInfo){ return view('backend.setting.edit',['companyInfo'=>$companyInfo]); } return view('backend.setting.create'); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { // if(!auth()->user()->canEvent('basic_setting')) // { // return redirect('/'); // } $companyInfo= CompanyInfo::first(); //dd( $companyInfo); if($companyInfo){ return view('backend.setting.basicEdit',['companyInfo'=>$companyInfo]); } return redirect()->route('setting'); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $validator = \Validator::make($request->all(), [ 'company_name' => 'required|max:150', 'company_address' => 'required|max:150', 'company_phone' => 'required|max:20', //'company_logo_img' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048', //'company_logo_text' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048', ]); if ($validator->fails()) { return response()->json(['errors'=>$validator->errors()->all()]); }else{ if($request->form == 'new'){ //logo img $logo_img=""; if ($request->hasFile('logo')) { if ($request->file('logo')->isValid()) { $image = $request->file('logo'); $logo_img= 'company_log_img'.date('_Y-m-d_H-i-s'). '.' . $image->getClientOriginalExtension(); $image->move(public_path('images/company'), $logo_img); }else{ return response()->json(['errors'=>['imag'=>'image not valid']]); } } $companyInfo = new CompanyInfo; $companyInfo->company_name = $request->company_name; $companyInfo->company_address = $request->company_address; $companyInfo->company_phone = $request->company_phone; $companyInfo->company_email = $request->company_email; // $companyInfo->minimum_stock_qty = $request->minimum_stock_qty ? $request->minimum_stock_qty : 0; $companyInfo->company_facebook =$request->company_facebook; $companyInfo->twitter =$request->twitter; $companyInfo->instagram =$request->instagram; $companyInfo->linkedin =$request->linkedin; $companyInfo->youtube =$request->youtube; $companyInfo->company_logo = $logo_img; // $companyInfo->company_logo_text = $logo_text; $companyInfo->save(); }else{ $logo_img=""; //return date('Y-m-d_H:i:s'); if ($request->hasFile('logo')) { if ($request->file('logo')->isValid()) { $image = $request->file('logo'); $logo_img= 'company_log_img'.date('_Y-m-d_H-i-s'). '.' . $image->getClientOriginalExtension(); $image->move(public_path('images/company'), $logo_img); unlink(public_path('images/company/'.$request->oldfile)); }else{ return response()->json(['errors'=>['imag'=>'image not valid']]); } } // return CompanyInfo::find(1); $companyInfo = CompanyInfo::find(1); $companyInfo->company_name = $request->company_name; $companyInfo->company_address = $request->company_address; $companyInfo->company_phone = $request->company_phone; $companyInfo->company_email = $request->company_email; // $companyInfo->minimum_stock_qty = $request->minimum_stock_qty ? $request->minimum_stock_qty : 0; $companyInfo->facebook =$request->company_facebook; $companyInfo->twitter =$request->twitter; $companyInfo->instagram =$request->instagram; $companyInfo->linkedin =$request->linkedin; $companyInfo->youtube =$request->youtube; if($logo_img){ $companyInfo->company_logo = $logo_img; } $companyInfo->save(); } } return response()->json(['errors'=>'0','success'=>'Record is successfully added']); } /** * Display the specified resource. * * @param \App\Models\CompanyInfo $companyInfo * @return \Illuminate\Http\Response */ public function show(CompanyInfo $companyInfo) { // } /** * Show the form for editing the specified resource. * * @param \App\Models\CompanyInfo $companyInfo * @return \Illuminate\Http\Response */ public function edit(CompanyInfo $companyInfo) { // } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param \App\Models\CompanyInfo $companyInfo * @return \Illuminate\Http\Response */ public function update(Request $request, CompanyInfo $companyInfo) { $validator = \Validator::make($request->all(), [ 'minimum_stock_qty' => 'max:100', ]); if ($validator->fails()) { return response()->json(['errors'=>$validator->errors()->all()]); }else{ if($request->form == 'new'){ $companyInfo = new CompanyInfo; $companyInfo->minimum_stock_qty = $request->minimum_stock_qty ? $request->minimum_stock_qty : 0; $companyInfo->rating_a = $request->rating_a ? $request->rating_a : 0; $companyInfo->rating_b = $request->rating_b ? $request->rating_b : 0; $companyInfo->rating_c =$request->rating_c ? $request->rating_c : 0; $companyInfo->rating_d = $request->rating_d ? $request->rating_d : 0; $companyInfo->rating_e = $request->rating_e ? $request->rating_e : 0; $companyInfo->rating_f = $request->rating_f ? $request->rating_f : 0; $companyInfo->save(); }else{ $companyInfo = CompanyInfo::find(1); $companyInfo->minimum_stock_qty = $request->minimum_stock_qty ? $request->minimum_stock_qty : 0; $companyInfo->rating_a = $request->rating_a ? $request->rating_a : 0; $companyInfo->rating_b = $request->rating_b ? $request->rating_b : 0; $companyInfo->rating_c =$request->rating_c ? $request->rating_c : 0; $companyInfo->rating_d = $request->rating_d ? $request->rating_d : 0; $companyInfo->rating_e = $request->rating_e ? $request->rating_e : 0; $companyInfo->rating_f = $request->rating_f ? $request->rating_f : 0; $companyInfo->save(); } } return response()->json(['errors'=>'0','success'=>'Record is successfully added']); } /** * Remove the specified resource from storage. * * @param \App\Models\CompanyInfo $companyInfo * @return \Illuminate\Http\Response */ public function destroy(CompanyInfo $companyInfo) { // } }