【发布时间】:2015-12-16 14:25:36
【问题描述】:
我在我的项目中使用 laravel 4。 我对 4 个表的选择结果进行了分页,我想将它们传递到一个变量中查看。
$vehicles = DB::table('vehicle')->orderBy('postTime','DESC')->paginate(8);
$estates = DB::table('estate')->orderBy('postTime','DESC')->paginate(8);
$tradings = DB::table('trading')->orderBy('postTime','DESC')->paginate(8);
$jobs = DB::table('job')->orderBy('postTime','DESC')->paginate(8);
但我无法使用 array_merge() 合并它们。分页后我也试过->to_array(),还是不行。
有人可以帮我吗?
编辑
正如@Turgut Sarıçam 建议的那样,我使用getItems() 作为我的结果,这是我的代码:
public static function index(){
$minVehicle = DB::table('vehicle')->min('price');
$maxVehicle = DB::table('vehicle')->max('price');
$minEstate = DB::table('estate')->min('price');
$maxEstate = DB::table('estate')->max('price');
$minTrading = DB::table('trading')->min('price');
$maxTrading = DB::table('trading')->max('price');
if($minVehicle == 'توافقی')
$minVehicle = 0;
if($maxVehicle == 'توافقی')
$maxVehicle = 0;
if($minEstate == 'توافقی')
$minEstate = 0;
if($maxEstate == 'توافقی')
$maxEstate = 0;
if($minTrading == 'توافقی')
$minTrading = 0;
if($maxTrading == 'توافقی')
$maxTrading = 0;
$vehicles = DB::table('vehicle')->orderBy('postTime','DESC')->paginate(8);
$estates = DB::table('estate')->orderBy('postTime','DESC')->paginate(8);
$tradings = DB::table('trading')->orderBy('postTime','DESC')->paginate(8);
$jobs = DB::table('job')->orderBy('postTime','DESC')->paginate(8);
$allResults = array_merge($vehicles,$jobs);
//echo "<meta charset='UTF8'><pre>";
//return die(print_r($allResults));
return View::make('search')->with(
array(
'minVehicle' => $minVehicle,
'maxVehicle' => $maxVehicle,
'minEstate' => $minEstate,
'maxEstate' => $maxEstate,
'minTrading' => $minTrading,
'maxTrading' => $maxTrading,
'ads' => $allResults
)
);
}
转储 $allResults(我评论过的地方)有一些结果。 我无法显示确切的结果,但这里是它的示例:
Array
(
[0] => stdClass Object
(
[id] => 243
[tableName] => vehicle
)
[1] => stdClass Object
(
[id] => 239
[tableName] => vehicle
)
[2] => stdClass Object
(
[id] => 235
[tableName] => vehicle
)
[3] => stdClass Object
(
[id] => 231
[tableName] => vehicle
)
[4] => stdClass Object
(
[id] => 227
[tableName] => vehicle
)
[5] => stdClass Object
(
[id] => 223
[tableName] => vehicle
)
[6] => stdClass Object
(
[id] => 219
[tableName] => vehicle
)
[7] => stdClass Object
(
[id] => 215
[tableName] => vehicle
)
[8] => stdClass Object
(
[id] => 4
[tableName] => job
)
[9] => stdClass Object
(
[id] => 3
[tableName] => job
)
)
虽然结果似乎是公平的,但没有返回任何视图。只是一张白纸
【问题讨论】:
-
你能复制你的代码而不是截图吗?
-
当然。看看编辑2
-
die(print_r($allResults)) 的结果是什么
-
@MwaaJoseph 添加到问题正文中;
-
然后尝试传递 $allResults->toArray();
标签: php laravel laravel-4 pagination laravel-pagination