Пример #1
0
 public function index()
 {
     $agencies = Agency::orderBy('group_id', 'ASC')->orderBy('position', 'ASC')->get();
     $agency = new Agency();
     if (Request::isMethod('post')) {
         $validator = Validator::make(Request::all(), $this->rules);
         if ($validator->passes()) {
             $agency->title = Request::input('title');
             $agency->text = Request::input('text');
             $agency->eng = Request::input('eng');
             $agency->group_id = Request::input('group');
             $agency->link = Request::input('link');
             $agency->position = Request::input('position');
             $agency->enabled = Request::has('enabled');
             if ($file = Request::file('photo')) {
                 $agency->photo = $this->upload($file, 'photo');
             }
             $agency->save();
             return redirect('admin/agency')->with('msg', 'Агентство было успешно создано');
         } else {
             return redirect('admin/agency')->withInput()->withErrors($validator);
         }
     }
     return view('admin.agency', ['agencies' => $agencies, 'agency' => $agency]);
 }
Пример #2
0
 /**
  * Creates a new Agency model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Agency();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }