【发布时间】:2019-10-31 20:23:59
【问题描述】:
我想从数据库中获取一些结果,并且原始 sql 查询在 phpmyadmin 中运行时会给出正确的输出,但 laravel 会给出空数组。
$transectionDetails=Wallet_transaction::query();
$transectionDetails->select('kitchen_name','parent_id',DB::raw("CONCAT(f_name, ' ', l_name) AS name"),'transaction_amount','transaction_time','transaction_id')
->join('parent_details','wallet_transactions.parent_id', '=','parent_details.id')
->join('kitchens','parent_details.kitchen_id', '=','kitchens.id')
->whereNotNull('wallet_transactions.transaction_id')
->where('wallet_transactions.transaction_for',2);
if(!empty($post_data) && $post_data['parent_name'] != ''){
$transectionDetails->where(DB::raw("CONCAT(f_name, ' ', l_name)"), 'like', "'%".$post_data['parent_name'] ."%'");
// echo '<pre>';var_dump(get_class_methods($transectionDetails));
echo '<pre>';var_dump($transectionDetails->toSql());
echo '<pre>';var_dump($transectionDetails->get());die;
}
var_dump($transectionDetails->get());die;
这给出了空数组,但数据库给出了正确的数组。
var_dump($transectionDetails->toSql());
给出:
select `kitchen_name`, `parent_id`, CONCAT(f_name, ' ', l_name) AS name,
`transaction_amount`, `transaction_time`, `transaction_id` from
`wallet_transactions` inner join `parent_details` on
`wallet_transactions`.`parent_id` = `parent_details`.`id` inner join
`kitchens` on `parent_details`.`kitchen_id` = `kitchens`.`id` where
`wallet_transactions`.`transaction_id` is not null and
`wallet_transactions`.`transaction_for` = ? and CONCAT(f_name, ' ',
l_name) like ?
有什么问题???**
【问题讨论】:
-
第二个是给你查询,而不是结果,检查你在查询中做错了什么,这样它就不会返回任何结果。
-
试试
$transectionDetails = $transectionDetails->get()或$transectionDetails = $transectionDetails->select(...)然后var_dump。
标签: php mysql laravel-5 eloquent mysql-workbench