mardi 18 juin 2019

Laravel collection fetch empty array but sql gives proper results

I want to fetch some result from database and the raw sql query give proper outputs when run in phpmyadmin but laravel give empty array.

    $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; this give empty array but database give proper array. var_dump($transectionDetails->toSql()); gives---

  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 ?

what is wrong in it???**



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire