user()->id; $admin = CompanyAdmin::where('user_id', $userId)->get(); if ($admin->count() == 1) { $agent = $admin->first(); $company = Company::find($agent->company_id); } else { abort(code: 401); } ; $details = new Details($company); $details = $details->details; if ($company->type == 'SELFEMP') { return view('company.details.selfemp', [ 'company' => $company, 'details' => $details ]); } ; if ($company->type == 'AGENCY') { return view('company.details.agency', [ 'company' => $company, 'details' => $details ]); } ; } public function store(Request $request, Company $company) { $userId = auth()->user()->id; $agent = Agent::where('user_id', $userId)->get(); if ($agent->count() == 1) { $agent = $agent->first(); if ($agent->company_id != $company->id) { return; } } else { return back(); } ; $company->details = $request->all(); $company->save(); return to_route('company.details', [ 'company' => $company ]); } }