/** * store Business * * @param BusinessFormRequest $request Business form Request * @return Response Redirect */ public function store(BusinessFormRequest $request) { $this->log->info('Manager\\BusinessController@store'); // Search Existing $existingBusiness = Business::withTrashed()->where(['slug' => $request->input('slug')])->first(); // If found if ($existingBusiness !== null) { $this->log->info("Manager\\BusinessController@store: Found existing businessId:{$existingBusiness->id}"); // If owned, restore if (auth()->user()->isOwner($existingBusiness)) { $this->log->info("Manager\\BusinessController@store: Restoring owned businessId:{$existingBusiness->id}"); $existingBusiness->restore(); Flash::success(trans('manager.businesses.msg.store.restored_trashed')); return redirect()->route('manager.business.service.create', $existingBusiness); } # If not owned, return message $this->log->info("Manager\\BusinessController@store: Already taken businessId:{$existingBusiness->id}"); Flash::error(trans('manager.businesses.msg.store.business_already_exists')); return redirect()->route('manager.business.index'); } // Register new Business $business = new Business($request->all()); $category = Category::find($request->get('category')); $business->strategy = $category->strategy; $business->category()->associate($category); $business->save(); auth()->user()->businesses()->attach($business); auth()->user()->save(); // Generate local notification $business_name = $business->name; Notifynder::category('user.registeredBusiness')->from('App\\User', auth()->user()->id)->to('App\\Business', $business->id)->url('http://localhost')->extra(compact('business_name'))->send(); // Redirect success Flash::success(trans('manager.businesses.msg.store.success')); return redirect()->route('manager.business.service.create', $business); }
public function handleCreate(FRV_business $request) { $business = new Business($request->all()); $user = User::where('id', '=', Auth::id())->first(); $business->user_id = $user->id; $business->code = Request::input('code'); $business->title = Request::input('title'); $business->about_us = Request::input('about_us'); $business->biodata = Request::input('biodata'); //get the current date $date_of_listing = date("Y-m-d"); $business->date_of_listing = $date_of_listing; $business->amount = Request::input('amount_to_loan'); $business->tenor = Request::input('tenor'); $business->repayment = Request::input('repayment'); $business->target_interest_rate = Request::input('target_interest_rate'); $business->projectS_fee = Request::input('projects_fee'); $business->purpose = Request::input('purpose'); $business->business_status = 'pending'; $business->save(); return Redirect::action('BusinessController@showBusiness')->with('message', 'Thank you for requesting a business loan! You can check your business loan detail by clicking DETAIL button!'); }
/** * post Import * * @param Business $business Business to import Contacts to * @param Request $request Submitted form data * @return Response Redirect to Business addressbook */ public function postImport(Business $business, Request $request) { $this->log->info("BusinessContactImportExportController: postImport: businessId:{$business->id}"); $csv = $this->csvToArray(Request::get('data')); foreach ($csv as $import) { $import = array_map(function ($item) { return $item == 'NULL' ? null : $item; }, $import); if ($import['birthdate'] !== null) { $date = \DateTime::createFromFormat('Ymd', $import['birthdate']); $import['birthdate'] = $date->format('m/d/Y'); } $notes = $import['notes']; unset($import['notes']); $contact = Contact::create($import); $business->contacts()->attach($contact, ['notes' => $notes]); $business->save(); } $count = count($csv); $this->log->info("BusinessContactImportExportController: Imported {$count} contacts to businessId:{$business->id}"); Notifynder::category('user.importedContacts')->from('App\\User', auth()->user()->id)->to('App\\Business', $business->id)->url('http://localhost')->extra(compact('count'))->send(); Flash::success(trans('manager.contacts.msg.import.success')); return redirect()->route('manager.business.contact.index', [$business]); }