Tuesday, 15 August 2017

Custom Queries In laravel

Here are the Custom Queries In laravel, please check it:

1. Date Format in laravel:

DB::raw('DATE_FORMAT(orders.timestamp_order_made, "%m/%d/%Y") as order_date')


2. Case Statement In Laravel

DB::raw("
                    CASE orders.status
                        WHEN '1' THEN 'Order Placed'
                        WHEN '2' THEN 'Allocated'
                        WHEN '3' THEN 'Rejected'
                        WHEN '4' THEN 'Failure'
                        WHEN '5' THEN 'Accepted'
                        WHEN '6' THEN 'Delivered'
                        WHEN '7' THEN 'Accepted by dispensary'
                        WHEN '8' THEN 'Pickup at dispensary'
                        ELSE 'NO'
                        END as order_status

                ")

3. Concatenation in Laravel:

DB::raw("CONCAT_WS(' ',users.first_name, users.last_name) AS customer_name")


Enjoy☺

2 comments:

  1. Can you please add more queries for laravel.
    Thank you

    ReplyDelete

Google Map Filter Api Example

Here is Google Map Filter Api Example: