/** * @param $petId * @return \Illuminate\Http\JsonResponse */ public function index($petId) { /** @var Pet $pet */ $pet = Pet::find($petId); $this->authorize('index', $pet); return $this->outputList($pet->photos()); }
/** * @param $petId * @return \Illuminate\Http\JsonResponse */ public function show($petId) { /** @var Pet $pet */ $pet = Pet::find($petId); if (!$pet) { return $this->notFound($petId, Pet::class); } $this->authorize('show', $pet); return $this->output($pet); }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Pet::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('brood', true, "INNER JOIN"); $query->andFilterWhere(['id' => $this->id, 'date_create' => $this->date_create, 'date_update' => $this->date_update, 'gender' => $this->gender, 'is_our_pet' => $this->is_our_pet, 'size' => $this->size, 'brood_id' => $this->brood_id, 'breed_id' => $this->breed_id, 'pet_status_id' => $this->pet_status_id]); $query->andFilterWhere(['like', 'name', $this->name]); $query->andFilterWhere(['like', 'description', $this->description]); $query->andFilterWhere(['like', 'titles', $this->titles]); $query->andFilterWhere(['like', 'color', $this->color]); $query->andFilterWhere(['like', 'mother_name', $this->father_name]); $query->andFilterWhere(['like', 'mother_link', $this->father_link]); $query->andFilterWhere(['like', 'father_name', $this->father_name]); $query->andFilterWhere(['like', 'father_link', $this->father_link]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getPet() { return $this->hasOne(Pet::className(), ['id' => 'pet_id']); }
/** * @return \yii\db\ActiveQuery */ public function getPuppies() { return $this->hasMany(Pet::className(), ['brood_id' => 'id'])->onCondition('pet.is_our_pet = ' . Pet::NOT_IS_OUR_PET); }
/** * Get all pet * * @return json */ public function getAllPets() { return Pet::all(); }
/** * Store pet into database * * @param array $input * @return boolean */ public function createPet($input) { $result = Pet::validate($input); if (!is_bool($result)) { return $this->setMessage($result); } $pet = new Pet(); $pet->pet_name = $input['name']; $pet->description = $input['description']; $pet->save(); return $result; }
public function actionPet($id) { $model = Pet::findOne($id); if (!$model) { throw new NotFoundHttpException('The requested page does not exist.'); } return $this->render('pet', ['model' => $model]); }
/** * @return \yii\db\ActiveQuery */ public function getPets() { return $this->hasMany(Pet::className(), ['pet_status_id' => 'id']); }
/** * Finds the Pet model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Pet the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Pet::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }