这是模型:
class TappaItinerario extends Model{
protected $table = "TappaItinerario";
protected $primaryKey = ['ref_idFermata', 'ref_codiceLinea', 'orarioTappa'];
public $incrementing = false;
public $timestamps = false;
public static function listStops($start, $end)
{
$tester = TappaItinerario::select('ref_codiceLinea')
->distinct()
->whereExists(function ($query) use ($start, $end) {
$query->select()
->from('' . (new static)->getTable() . ' AS T2')
->join('' . (new static)->getTable() . ' AS T3', 'T2.orarioTappa', '<', 'T3.orarioTappa')
->where([
['T2.ref_codiceLineas', '=', '' . (new static)->getTable() . '.ref_codiceLinea'],
['T3.ref_codiceLinea', '=', '' . (new static)->getTable() . '.ref_codiceLinea'],
['T2.tipoTappa', '=', 'A'],
['T3.tipoTappa', '=', 'A'],
['T2.ref_idFermata', '=', $start],
['T3.ref_idFermata', '=', $end]
]);
})
->orWhereExists(function ($query) use ($start, $end) {
$query->select()
->from('' . (new static)->getTable() . ' AS T2')
->join('' . (new static)->getTable() . ' AS T3', 'T2.orarioTappa', '<', 'T3.orarioTappa')
->where([
['T2.ref_codiceLinea', '=', '' . (new static)->getTable() . '.ref_codiceLinea'],
['T3.ref_codiceLinea', '=', '' . (new static)->getTable() . '.ref_codiceLinea'],
['T2.tipoTappa', '=', 'R'],
['T3.tipoTappa', '=', 'R'],
['T2.ref_idFermata', '=', $start],
['T3.ref_idFermata', '=', $end]
]);
})
->get();
return $tester;
}}
如果我尝试启动它,Laravel会给我完整的停靠点清单。
但是,如果使用相同的查询,则从sql正常启动,并使我仅显示一站式。
我指定从数据库启动的查询是从laravel生成的,然后将其复制以启动它。这样就不会有参数错误或其他任何事情。
我不知道如何解决问题。你有什么想法吗?