Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mutant3's avatar

Convert query

Hi, i need convert this query to SQL, I am very new developer.

    $contents = Publish::select('id', 'time_to_air', 'date' ,'position')
        ->where('emission_id', $request->emission->id)->with(['files' => function($query) {
            $query->select('url', 'md5');
        }])->orderBy('position', 'ASC')
        ->get();

Thanks

0 likes
3 replies
tisuchi's avatar

@mutant3 You can use ->toSql().


   $contents = Publish::select('id', 'time_to_air', 'date' ,'position')
        ->where('emission_id', $request->emission->id)->with(['files' => function($query) {
            $query->select('url', 'md5');
        }])->orderBy('position', 'ASC')
        ->get()
        ->toSql();
4 likes
tisuchi's avatar
tisuchi
Best Answer
Level 70

@mutant3 Have you tried this?

You just do dd($contents) that will give you a plain SQL.

Ofcourse, you may need to adjust the request values.

5 likes

Please or to participate in this conversation.