예제 #1
0
 public function ModelEditView($clid, $advid, $mdlid)
 {
     if (!is_null($mdlid)) {
         if (Auth::check()) {
             if (in_array('ADD_EDIT_MODEL', $this->permission)) {
                 if (User::isSuperAdmin()) {
                     $offer = Offer::get();
                     $model_obj = ModelTable::with(['getAdvertiser' => function ($q) {
                         $q->with('GetClientID');
                     }])->find($mdlid);
                 } else {
                     $usr_company = $this->user_company();
                     $model_obj = ModelTable::whereHas('getAdvertiser', function ($q) use($usr_company) {
                         $q->whereHas('GetClientID', function ($p) use($usr_company) {
                             $p->whereIn('user_id', $usr_company);
                         });
                     })->find($mdlid);
                     $offer = Offer::whereHas('getAdvertiser', function ($q) use($usr_company) {
                         $q->whereHas('GetClientID', function ($p) use($usr_company) {
                             $p->whereIn('user_id', $usr_company);
                         });
                     })->get();
                 }
                 if (!$model_obj) {
                     return Redirect::back()->withErrors(['success' => false, 'msg' => 'please Select your Client'])->withInput();
                 }
                 $positive_offer_id = array();
                 $negative_offer_id = array();
                 if (!is_null($model_obj->positive_offer_id)) {
                     $positive_offer_id = explode(',', $model_obj->positive_offer_id);
                 }
                 if (!is_null($model_obj->negative_offer_id)) {
                     $negative_offer_id = explode(',', $model_obj->negative_offer_id);
                 }
                 return view('model.edit')->with('offer_obj', $offer)->with('positive_offer_id', $positive_offer_id)->with('negative_offer_id', $negative_offer_id)->with('model_obj', $model_obj);
             }
             return Redirect::back()->withErrors(['success' => false, 'msg' => "You don't have permission"]);
         }
         return Redirect::to(url('/user/login'));
     }
 }