我正在为我的项目使用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()
,它没有用。
有人可以帮助我吗?
修改
正如@TurgutSarıç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
)
)
虽然结果似乎公平,但没有返回任何视图。只是一个空白的白页
答案 0 :(得分:0)
你应该先拿到物品。试试这样:
$allResults = array_merge($vehicles->items(), $estates->items(), $tradings->items(), $jobs->items());
编辑:我猜你可以在Laravel 4中获得具有getItems()功能的项目。上面是Laravel 5,我的不好。
答案 1 :(得分:0)
您正在处理从查询返回的集合。不要认为数组合并是正确的方法尝试使用集合合并。
laravel 4也支持集合合并。 尝试使用此
<ul class="dropdown-menu" role="menu">
<li><a href="read_message.php" type="submit" method="post">Mark as read</a></li>
<li><a href="unread_message.php">Mark as unread</a></li>
<li class="divider"></li>
<li><a href="move_junck.php">Move to junk</a></li>
<li class="divider"></li>
<li><a href="delete.php">Delete</a></li>
</ul>