예제 #1
0
 /**
  * @return mixed
  */
 public function store()
 {
     $input = \Request::all();
     $validator = \Validator::make($input, ['owner_id' => 'required', 'property_name' => 'required|max:255']);
     if ($validator->fails()) {
         \App::abort(400, $validator->messages()->first());
     }
     $property = new Property($input);
     $owner = Owner::find($input['owner_id']);
     $property = $owner->Properties()->save($property);
     return \Response::json(['success' => true, 'message' => 'Property Created.', 'data' => $property]);
 }
예제 #2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Owner::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->joinWith(['images', 'images.tags']);
     $query->groupBy(['owner.id']);
     $query->andFilterWhere(['owner.id' => $this->id, 'image.id' => $this->image_id, 'tag.id' => $this->tag_id]);
     $query->andFilterWhere(['like', 'dns', $this->dns]);
     return $dataProvider;
 }
예제 #3
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Owner::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->setSort(['attributes' => ['id', 'fullName' => ['asc' => ['first_name' => SORT_ASC, 'last_name' => SORT_ASC], 'desc' => ['first_name' => SORT_DESC, 'last_name' => SORT_DESC], 'default' => SORT_ASC], 'license', 'state_id', 'city', 'zip_code', 'email', 'vehicleName' => ['asc' => ['Vehicle.make' => SORT_ASC, 'Vehicle.model' => SORT_ASC], 'desc' => ['Vehicle.make' => SORT_DESC, 'Vehicle.model' => SORT_DESC], 'default' => SORT_ASC]]]);
     if (!($this->load($params) && $this->validate())) {
         $query->joinWith(['vehicle']);
         return $dataProvider;
     }
     $query->andWhere('first_name LIKE "%' . $this->fullName . '%" ' . 'OR last_name LIKE "%' . $this->fullName . '%"');
     $query->andFilterWhere(['id' => $this->id, 'state_id' => $this->state_id]);
     $query->andFilterWhere(['like', 'license', $this->license])->andFilterWhere(['like', 'city', $this->city])->andFilterWhere(['like', 'zip_code', $this->zip_code])->andFilterWhere(['like', 'email', $this->email]);
     $query->joinWith(['vehicle' => function ($query) {
         $query->where('Vehicle.make LIKE "%' . $this->vehicleName . '%"' . 'OR Vehicle.model LIKE "%' . $this->vehicleName . '%"');
     }]);
     return $dataProvider;
 }
예제 #4
0
 /**
  * Register any other events for your application.
  *
  * @param  \Illuminate\Contracts\Events\Dispatcher  $events
  * @return void
  */
 public function boot(DispatcherContract $events)
 {
     parent::boot($events);
     \App\Models\Owner::saving(function ($owner) {
         if (empty($owner->owner_name)) {
             $owner->owner_name = null;
         }
         $owner->org_id = \Auth::User()->org_id;
         return $owner;
     });
     \App\Models\Property::saving(function ($property) {
         if (empty($property->property_name)) {
             $property->property_name = null;
         }
         $property->org_id = \Auth::User()->org_id;
         return $property;
     });
     \App\Models\Unit::saving(function ($unit) {
         if (empty($unit->unit_name)) {
             $unit->unit_name = null;
         }
         $unit->org_id = \Auth::User()->org_id;
         return $unit;
     });
     \App\Models\Tenant::saving(function ($tenant) {
         if (empty($tenant->tenant_name)) {
             $tenant->tenant_name = null;
         }
         $tenant->org_id = \Auth::User()->org_id;
         return $tenant;
     });
     \App\Models\Transaction::saving(function ($transaction) {
         $transaction->org_id = \Auth::User()->org_id;
         return $transaction;
     });
 }
예제 #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getOwner()
 {
     return $this->hasOne(Owner::className(), ['id' => 'owner_id']);
 }
예제 #6
0
 /**
  * Deletes an existing Owner model.
  * If deletion is successful, the browser will be redirected to the 'manage' page.
  * @param integer $id
  * @return mixed
  */
 public function actionDelete($id)
 {
     $this->findModel(Owner::className(), $id)->delete();
     return $this->redirect(['manage']);
 }
예제 #7
0
 /**
  *
  * @param $id
  * @return Response
  */
 public function destroy($id)
 {
     $transaction = Owner::findOrFail($id);
     $transaction->delete();
     return \Response::json(['success' => true, 'message' => 'Owner Deleted.', 'data' => []]);
 }
 /**
  * Finds the Owner model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Owner the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Owner::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }