logo
Tags down

shadow

group_concat in mysql laravel


By : SpiderMan
Date : May 05 2020, 09:02 AM

Here is code query in mySQL. i want to convert into Laravel query.

becuase query is not effected on Laravel blade. so I need to convert in Laravel query. can anyone know how to do this ?

Laravel Controller :

   class BookingDetailsController extends Controller
   {
       public function booking_list()
       {
           $role = Auth::user()->role;

           $data['page_title'] = "Booking Detail";
           $data['page_description'] = "Welcome to Admin Dashboard"; 
            $booking_detail = DB::select('SELECT bd.id as book_id, bd.recept_no, bd.advance_payment,bd.total_balance,
                               bd.is_booked, cc.name,  GROUP_CONCAT(dcb.rate SEPARATOR \'|\'), 
                               GROUP_CONCAT(dcb.pickup_point SEPARATOR \'|\'),  
                               GROUP_CONCAT(dcb.drop_point SEPARATOR \'|\'),  
                               GROUP_CONCAT(cn.car_number SEPARATOR \'|\') FROM booking_details bd
                               left join driver_car_booking_details dcb on bd.id = dcb.booking_id
                               left join car_nos cn on dcb.vehicle_id = cn.id
                               inner join customers cc on bd.customer_id = cc.id
                               group by bd.id
                               order by bd.id' ); 

           if($role == 'admin'){
               dd($booking_detail);
               return view('admin.booking_list')->with($data)
               ->with('booking_detail', $booking_detail);
           }
           if($role == 'oil_filling'){
               return view('oil_filling.booking_list')->with($data)
               ->with('booking_detail', $booking_detail);
           }else{
               return view('admin.booking_list')->with($data)
               ->with('booking_detail', $booking_detail);
           }

       }
}

the raw query like :

<?php
 SELECT bd.id as book_id, bd.recept_no, bd.advance_payment,bd.total_balance, bd.is_booked, cc.name, GROUP_CONCAT(dcb.rate SEPARATOR '|'), GROUP_CONCAT(dcb.pickup_point SEPARATOR '|'), GROUP_CONCAT(dcb.drop_point SEPARATOR '|'), GROUP_CONCAT(cn.car_number SEPARATOR '|') FROM booking_details bd left join driver_car_booking_details dcb on bd.id = dcb.booking_id left join car_nos cn on dcb.vehicle_id = cn.id inner join customers cc on bd.customer_id = cc.id group by bd.id order by bd.id
Answer :

The raw query builder methods can used to execute queries without using the ORM.

The next snippet would execute the above query:

   <?php   $bookings = DB::select('SELECT bd.id as book_id, bd.recept_no, bd.advance_payment,bd.total_balance,
        bd.is_booked, cc.name,  GROUP_CONCAT(dcb.rate SEPARATOR \'|\'), 
GROUP_CONCAT(dcb.pickup_point SEPARATOR \'|\'),  
GROUP_CONCAT(dcb.drop_point SEPARATOR \'|\'),  
GROUP_CONCAT(cn.car_number SEPARATOR \'|\') FROM booking_details bd
        left join driver_car_booking_details dcb on bd.id = dcb.booking_id
        left join car_nos cn on dcb.vehicle_id = cn.id
        inner join customers cc on bd.customer_id = cc.id
        group by bd.id
        order by bd.id');


Share : facebook icon twitter icon
Related Posts Related Posts :
  • clear array after form submit
  • pass url variable to javascript
  • access data using api
  • div position fixed css
  • add horizontal line between two div
  • disable toggle button css
  • css fixed line height
  • background image not working
  • table cell border
  • text line break css
  • overlay div on div
  • text direction rtl css
  • javascript convert string to an object
  • bind inner div click to outer div
  • jquery ajax oncomplete
  • how to use promise in for loop
  • jquery get element using variable
  • javascript send textbox value
  • pass div class content to another class or id
  • css new line after element
  • css calc not working properly
  • link disabled jquery
  • sql join table to subquery
  • MS Access SQL Issue with OR AND Operators
  • set textarea value using php
  • php merge two arrays into one
  • php form with google captcha
  • update current row in php
  • php date format mysql
  • mysql pdo select query
  • php function return an array
  • PHP mysqldump database to sql file
  • display image query
  • php create array using foreach loop
  • associative array php
  • php array_push empty
  • mysql on update cascade not working
  • pdo insert prepared statement
  • mysql insert ignore vs on duplicate key
  • mysql insert into existing row
  • mysql multi insert query
  • mysql group by show all rows
  • php change profile image
  • combine multiple arrays into one array php
  • how to sum values in an array
  • how to get sum of the total time
  • How to Create Facebook live stream without notification using API ?
  • on button click make div visible
  • css affect another element on hover
  • insert line after paragraph word
  • shadow
    Privacy Policy - Terms - Contact Us © bighow.org