/**
  * store Business
  *
  * @param  BusinessFormRequest $request Business form Request
  * @return Response                     Redirect
  */
 public function store(BusinessFormRequest $request)
 {
     $this->log->info(__METHOD__);
     //////////////////
     // FOR REFACTOR //
     //////////////////
     // Search Existing
     $existingBusiness = Business::withTrashed()->where(['slug' => $request->input('slug')])->first();
     // If found
     if ($existingBusiness !== null) {
         $this->log->info("  Found existing businessId:{$existingBusiness->id}");
         // If owned, restore
         if (auth()->user()->isOwner($existingBusiness)) {
             $this->log->info("  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("  Already taken businessId:{$existingBusiness->id}");
         Flash::error(trans('manager.businesses.msg.store.business_already_exists'));
         return redirect()->back()->withInput(request()->all());
     }
     // 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\\Models\\User', auth()->user()->id)->to('App\\Models\\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);
 }
Beispiel #2
0
 /**
  * Set category to a Business and save.
  * 
  * @param Business $business
  * @param int      $category
  *
  * @return App\Models\Business
  */
 public function setCategory(Business $business, $category)
 {
     $category = Category::find($category);
     $business->category()->associate($category);
     $business->save();
     return $business;
 }