/** * 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); }