Laravel Query for MySQL Concat

Abrar Jahin

I have a table like this-

webinars

enter image description here

I want to have a query in Laravel Query Builder like this-

    // Base Query
    $baseQuery = DB::table('webinars')
        //->join('users', 'panelists.user_id', '=', 'users.id')
        ->select(
            'id',
            'title',
            'description',
            'hosts',
            DB::raw('concat(starts_on, ' ', timezone) as starts'),
            'duration',
            'created_at'
        )
        ->where('user_id', '=', $user_ID);

And getting error for-

     DB::raw('concat(starts_on, ' ', timezone) as starts')

I need it because I want something like =>

today JPN

if starts_on=today and timezone='JPN'

Can anyone pleae help?

Beginner

DB::raw('concat(starts_on, ' ', timezone) as starts')

:- You have added single quote inside single quote.

You can try this:

// Base Query
$baseQuery = DB::table('webinars')
    //->join('users', 'panelists.user_id', '=', 'users.id')
    ->select(
        'id',
        'title',
        'description',
        'hosts',
        DB::raw('concat(starts_on, " ", timezone) as starts'),
        'duration',
        'created_at'
    )
    ->where('user_id', '=', $user_ID);

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related