Красноречивые дублирующие привязки во втором вызове

Я использую Шаблон Reposity в проекте Laravel. Проблема в том, что я вижу, что это дублирует привязки во втором запросе вызова!

Это мой код:

class AirController extends Controller
{
private $airportService;

public function __construct(AirportService $airportService) {
$this->airportService = $airportService;
}

public function getAirports(){
$departure_airport = $this->airportService->getCityFromAirport("6");
$destiny_airport = $this->airportService->getCityFromAirport("10");
}
}

Отладка, $departure_airport получает запись, но $destiny_airport выходит из строя. Вы будете думать, что id: 10 есть проблема. Нету. Если я поменяюсь и поставлю $destiny_airport сначала он получает запись, но потом $departure_airport выходит из строя. Затем я подумал о печати необработанных SQL-запросов, как было предложено Вот.

Это результат:

INFO: "select * from `airports` where `airports`.`id` = ? limit 1"INFO: ["6"]
INFO: "select * from `cities` where `cities`.`id` = ? limit 1"INFO: [441]
*****************************************************************************************
INFO: "select * from `airports` where `airports`.`id` = ? and `airports`.`id` = ? limit 1"INFO: ["6","10"]

Почему в третьем запросе (после звездочек) дублируется столбец «id» с параметрами 6 и 10, когда я передаю в качестве параметра только 10 во втором запросе ?! Вместо третьего запроса мне бы хотелось вот так:

INFO: "select * from `airports` where `airports`.`id` = ? limit 1"INFO: ["10"]

Это реализация:

AirportService.php:

use App\Repositories\AirportRepository as Airport;

class AirportService {

private $airport;

public function __construct(Airport $airport){
$this->airport = $airport;
}

public function getCityFromAirport($airportId){
$airport = $this->airport->find($airportId);
return $airport->City;
}
}

Repository.php

...

public function find($id, $columns = array('*')) {
return $this->model->find($id, $columns);
}

...

IRepository.php

...

public function find($id, $columns = array('*'));

...

Данная ошибка:

local.ERROR: Trying to get property of non-object {"userId":41,"email":"...@...","exception":"[object] (ErrorException(code: 0): Trying to get property of non-object at C:\\wamp\\www\\project\\API\\app\\Services\\AirportService.php:21)

0

Решение

Попробуйте позвонить newModelInstance в методе поиска из хранилища.

return $this->model->newModelInstance()->find($id, $columns);
1

Другие решения

Других решений пока нет …

По вопросам рекламы ammmcru@yandex.ru
Adblock
detector