In laravel, the full name of orm is "Object-Relational Mapping", which means "object-relational mapping". Its function is to make a mapping between the relational database and business entity objects; in this way, when operating business objects, There is no need to deal with complex SQL statements, just operate the properties and methods of the object.
The operating environment of this tutorial: Windows 7 system, Laravel 6 version, Dell G3 computer.
What is ORM
ORM, the full name is Object-Relational Mapping, its function is to make a mapping between relational database and business entity objects , In this way, when we operate specific business objects, we no longer need to deal with complex SQL statements, we only need to simply operate the properties and methods of the objects.
ORM implementation method
The two most common implementation methods are ActiveRecord and DataMapper (the former is used in laravel)
- # Models in ##ActiveRecord (very popular) correspond to data tables one-to-one, while models and data tables in
- DataMapper are completely separated.
Understand the two magic functions __call () and __callStatic ()
class Test{ //动态调用的时候 没有找到此函数 则执行__call() 方法 public function __call($method, $parameters){ echo 22222222222; return (new Rest)->$method(...$parameters); } //静态调用的时候 没有找到此函数 则执行__callStatic()方法 public static function __callStatic($method, $parameters){ echo 1111111111; return (new static)->$method(...$parameters); } } class Rest{ public function foo($name , $age){ echo 333; dump($name,$age); } } //先调用了__callStatic(), 在调用__call(), 然后调用 foo(); Test::foo('张三',17); //只调用了 __call(), 然后调用 foo(); (new Test())->foo('李四',16);die;Understanding the first two magic functions will also understand the difficulties in laravel Eloqument ORM Now, let’s take a look at the source code in Model
/** * Handle dynamic method calls into the model. * * @param string $method * @param array $parameters * @return mixed */public function __call($method, $parameters) { if (in_array($method, ['increment', 'decrement'])) { return $this->$method(...$parameters); } return $this->newQuery()->$method(...$parameters); } /** * Handle dynamic static method calls into the method. * * @param string $method * @param array $parameters * @return mixed */public static function __callStatic($method, $parameters) { return (new static)->$method(...$parameters); }new static returns the caller’s instance, new self () returns its own instanceWhen using eloqument to query
$list = Politician::where('party_id', 1)->count();where method is not in Model, it will first execute the callStatic() function to obtain the App\Models\Politician instance, then execute call (), and look for where () count(), etc. in the instance returned by $this->newQuery () method. Take a closer look at the instance returned by the newQuery () method. After understanding these two magic functions, the difficulty of implementing ORM in laravel can be overcome.
The query constructor in laravel
$list = DB::table('categoty')->get();Eloquent ORM actually encapsulates the query construction, making it easier to operate. If you are interested in the source code of the query constructor, you can take a look[Related recommendations:
laravel video tutorial]
The above is the detailed content of what is laravel orm. For more information, please follow other related articles on the PHP Chinese website!

Laravel can be used for front-end development. 1) Use the Blade template engine to generate HTML. 2) Integrate Vite to manage front-end resources. 3) Build SPA, PWA or static website. 4) Combine routing, middleware and EloquentORM to create a complete web application.

PHP and Laravel can be used to build efficient server-side applications. 1.PHP is an open source scripting language suitable for web development. 2.Laravel provides routing, controller, EloquentORM, Blade template engine and other functions to simplify development. 3. Improve application performance and security through caching, code optimization and security measures. 4. Test and deployment strategies to ensure stable operation of applications.

Laravel and Python have their own advantages and disadvantages in terms of learning curve and ease of use. Laravel is suitable for rapid development of web applications. The learning curve is relatively flat, but it takes time to master advanced functions. Python's grammar is concise and the learning curve is flat, but dynamic type systems need to be cautious.

Laravel's advantages in back-end development include: 1) elegant syntax and EloquentORM simplify the development process; 2) rich ecosystem and active community support; 3) improved development efficiency and code quality. Laravel's design allows developers to develop more efficiently and improve code quality through its powerful features and tools.

Choosing Laravel or Python depends on the project requirements: 1) If the project is mainly web development and needs to quickly build complex applications, choose Laravel; 2) If data science, machine learning or more flexibility is involved, choose Python.

Laravel optimizes the web development process including: 1. Use the routing system to manage the URL structure; 2. Use the Blade template engine to simplify view development; 3. Handle time-consuming tasks through queues; 4. Use EloquentORM to simplify database operations; 5. Follow best practices to improve code quality and maintainability.

Laravel is a modern PHP framework that provides a powerful tool set, simplifies development processes and improves maintainability and scalability of code. 1) EloquentORM simplifies database operations; 2) Blade template engine makes front-end development intuitive; 3) Artisan command line tools improve development efficiency; 4) Performance optimization includes using EagerLoading, caching mechanism, following MVC architecture, queue processing and writing test cases.

Laravel's MVC architecture improves the structure and maintainability of the code through models, views, and controllers for separation of data logic, presentation and business processing. 1) The model processes data, 2) The view is responsible for display, 3) The controller processes user input and business logic. This architecture allows developers to focus on business logic and avoid falling into the quagmire of code.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft