Php 创建集合后删除Laravel查询结果&;翻页虫?
这个查询可以工作并返回我想要的结果,但一旦转换为集合或尝试“分页”,它将返回一个空结果。我尝试了对一个简单的Php 创建集合后删除Laravel查询结果&;翻页虫?,php,database,laravel,collections,eloquent,Php,Database,Laravel,Collections,Eloquent,这个查询可以工作并返回我想要的结果,但一旦转换为集合或尝试“分页”,它将返回一个空结果。我尝试了对一个简单的DB::table('users')->paginate(5)[0]进行分页,但效果很好,所以我猜它不是来自分页本身 代码 $photographers_available = Photographer::where('is_photographer', '=', '1') ->where(function($q)use($city_id)
DB::table('users')->paginate(5)[0]
进行分页,但效果很好,所以我猜它不是来自分页本身
代码
$photographers_available = Photographer::where('is_photographer', '=', '1')
->where(function($q)use($city_id)
{
$q->whereHas('studioAddress', function($q)use($city_id)
{
$q->where('city_id', '=', $city_id);
})
->orWhereHas('user', function($q)use($city_id) // TK could reduce to 'user.address' I think
{
$q->whereHas('address', function($q)use($city_id)
{
$q->where('city_id', '=', $city_id);
});
});
})
->whereHas('stypesPhotographer', function($q)use($stype)
{
$q->where('shooting_type_id', '=', $stype);
})
->whereHas('availabilities', function ($q) use ($selected_date_time)
{
$q->where('unavailable_start_date', '<', $selected_date_time)
->where('unavailable_end_date', '>', $selected_date_time);
}, '=', 0)
->whereHas('bookings', function($q)use($selected_date_time)
{
$q->where('booking_date', '=', $selected_date_time);
}, '=', 0)
->join('stypes_4_photographer', function($join)use($stype)
{
$join->on('photographer_id', '=', 'photographers.id')
->where('shooting_type_id', '=', $stype);
});
$photobla = $photographers_available->first();
echo '<pre>';print_r($photobla);
// RETURNS RESULTS CORRECTLY
$photoTEST = $photographers_available->get();
echo '<pre>';print_r($photoTEST);die();
// RETURNS $photoTEST as NULL.....
// WHY has $photographers_available BEEN EMPTIED?????
因此,您可以看到,$photophers\u可用
刚在->first()之后清空。最重要的是,即使在初始查询中直接使用paginate,它也无法工作
我建议你这样做(不要先打电话):
或者return
这个东西,而不是echo whataver
,因为这不是方法。在控制器中输出类似的内容会中断应用程序流
回答您遇到的问题,如评论中所述:将laravel/framework恢复到以前的版本(在本地/dev服务器中)Hi@jarek,我不确定我是否在关注您的问题。如果我做dd($摄影师可用->获取());是的,它会起作用的。我对第一个和第二个进行了排序和输出,以测试和发现问题。但是dd($Pictures_available->paginate(5)[0])返回未定义的偏移量:0您在那里有很多连接,这可能会破坏Paginator
功能,因为它有时与连接有关。谢谢,这很奇怪,因为在我昨天运行composer更新之前,它正在工作。。。。我能做些什么来修复它呢?在你的composer.json中使用require:{Laravel/framework:“4.2.YOUR\u VER”…
恢复以前的Laravel版本问题是我部署了应用程序,所以服务器运行的是最新版本,不能让他返回…有办法解决吗?:0
// $photobla result
Photographer Object
(
[fillable:protected] => Array
(
[0] => id
[1] => is_photographer
[2] => service_description
[3] => radius_around_city_available
[4] => tax_nbr
[5] => user_id
[6] => average_score
)
[table:protected] => photographers
[touches:protected] => Array
(
[0] => stypesPhotographer
)
[connection:protected] =>
[primaryKey:protected] => id
[perPage:protected] => 15
[incrementing] => 1
[timestamps] => 1
[attributes:protected] => Array
(
[id] => 677
[is_photographer] => 1
[ETC>>>>>>>>]
)
[original:protected] => Array
(
[id] => 677
[is_photographer] => 1
[ETC>>>>>>>>]
)
[relations:protected] => Array
(
)
[hidden:protected] => Array
(
)
[visible:protected] => Array
(
)
[appends:protected] => Array
(
)
[guarded:protected] => Array
(
[0] => *
)
[dates:protected] => Array
(
)
[observables:protected] => Array
(
)
[with:protected] => Array
(
)
[morphClass:protected] =>
[exists] => 1
)
// THE $photoTEST result:
Illuminate\Database\Eloquent\Collection Object
(
[items:protected] => Array
(
)
)
$photographers_available; // it is a query, consider other name
$photographers_available->first();
// set limit 1 on the query and return it's result
$photographers_available->get();
// returns the query result (remember limit 1 above..)
$photographers_available->paginate();
// return the query result paginated (ignoring limit 1 above)
dd($photographers_available->get());