Introduction
You can easily use Orator (Maurice Calhoun’s online tool) Convert native and legacy SQL statements into Laravel functional Query statements.
This online tool is also a great tool for you to learn Laravel ORM, it helps you convert SQL query statements into query builder objects, as learning a new ORM can sometimes become a challenge for new developers.
Use
You only need to enter your SQL statement and this tool will Will return a Laravel functional Query statement.
For example, take this SQL query:
select posts.id, posts.title, posts.body from posts where posts.author_id = 1 order by posts.published_at DESC limit 10;
The online tool converts it into the following Laravel functional Query statement:
DB::select('posts.id','posts.title','posts.body') ->from('posts') ->where('posts.author_id', '=', 1) ->orderBy('posts.published_at', 'DESC') ->limit(10) ->get();
One last thing to note, you The backticks (`) must be replaced with (') for proper use because this tool uses backticks when generating strings. PHP will try to execute the content in the backtick as a shell command. For details, see (Execution Operator).