Home  >  Article  >  PHP Framework  >  Teach you to use Orator to convert your SQL into Laravel Query statements

Teach you to use Orator to convert your SQL into Laravel Query statements

藏色散人
藏色散人forward
2020-07-30 13:30:343121browse

The following tutorial column from Laravel will introduce to you how to use Orator to convert your SQL into Laravel Query statements. I hope it will be helpful to friends in need!

Teach you to use Orator to convert your SQL into Laravel Query statements

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

Click here to try this tool

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).

The above is the detailed content of Teach you to use Orator to convert your SQL into Laravel Query statements. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:segmentfault.com. If there is any infringement, please contact admin@php.cn delete