Home > PHP Framework > Laravel > 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

藏色散人
Release: 2020-07-30 13:30:34
forward
3202 people have browsed it

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;
Copy after login

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();
Copy after login

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!

Related labels:
source:segmentfault.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template