【发布时间】:2020-03-29 09:34:27
【问题描述】:
我需要获取信息并将其放入数组中,但出现错误。
在进行 get 查询的类的代码下方
public function getByLoja(string $uuid): array
{
$query = HorarioLoja::all();
$query = $query->where('loja', function ($loja) use ($uuid) {
$loja->where('uuid', $uuid);
});
$horariosDaLoja = $query->get();
$saida = [];
foreach ($horariosDaLoja as $horario) {
$saida[] = $this->horarioLojaTransformador->paraModelo($horario);
}
return $saida;
}
型号代码下方
class HorarioLoja extends Model
{
protected $dates = ['created_at', 'updated_at'];
protected $table = 'horario_lojas';
public function loja()
{
return $this->belongsTo(Loja::class, 'loja_id', 'id');
}
}
错误:
函数 Illuminate\Support\Collection::get() 的参数太少,在第 32 行的 /var/www/html/code/app/Persistencia/Laravel/Repositorios/HorariosLojasRepositorioLaravel.php 中传递了 0,预计至少有 1 个{"exception":"[object] (Symfony\Component\Debug\Exception\FatalThrowableError(code: 0): 函数 Illuminate\Support\Collection::get() 的参数太少,0 传入 /var/www/html /code/app/Persistencia/Laravel/Repositorios/HorariosLojasRepositorioLaravel.php 位于第 32 行,预计至少 1 个位于 /var/www/html/code/vendor/laravel/framework/src/Illuminate/Support/Collection.php:874)
【问题讨论】:
标签: laravel