Table of Contents
回复内容:
Home Backend Development PHP Tutorial laravel5 为什么把模型直接放在App目录下?

laravel5 为什么把模型直接放在App目录下?

Jun 06, 2016 pm 08:10 PM
laravel php software design

如题,这样做肯定有他的目的,但是为什么呢?
另外,模型就是数据库吗,如果不是,他是什么?
laravel新手。

回复内容:

如题,这样做肯定有他的目的,但是为什么呢?
另外,模型就是数据库吗,如果不是,他是什么?
laravel新手。

laravel我也使用了一段时间
感觉确实不错
mvc在它里边弱化了很多
官方文档中甚至都没有提这个概念
它放在app目录的那个文件
我感觉应该是一个entity
一般来说一个entity对应一个表
而model这个是一个很广的概念
我理解它应该包含了业务逻辑,form验证,数据写入等
这应该是很复杂的东西
如果强制把这些所有的东西都放到entity中
会造成entity过胖的问题
不过这个文件放到哪里
我感觉只要你觉得合理
app目录下那个位置都可以
以上仅仅是我个人的想法
如有错误还请各位包含

模型就是获取数据的接口。
而大部分框架都用了orm,就是对象关系映射。将数据库中的表映射成一个编程语言中的对象,也就是模型。至于为什么放在app下面我也不知道,我也觉得放在一个文件夹里面更好。

我觉得
1- 你想太多了
2- 有点盲目崇拜

首先,不管是教程还是文档通常只是演示一种使用方式,而不是要求使用者死抄文档。
其次,有时候代码是带有非开发意义的。反正我现在还去看l5的东西,只是推测,可能l5里面优化RESTful,毕竟现在这种用法越来越普遍了,所以为了宣传自己主推的新特性干脆就这样弄demo了。对于RESTful来说,如果 l5 集成了RESTful路由、token或其他的安全机制,那么前端使用angular之类的框架时有model就够了。
最后,很多事没必要研究为什么。socket功能的源码往往伴随着一个聊天室的demo,难道我们使用这些源码构建socket应用的时候必须也实现一个聊天室吗?

laravel5 为什么把模型直接放在App目录下?

这样玩也是可以的。

我是把模型理解为那个表中记录的抽象,User的实例代表users表中每一个记录

这个问题,Laravel的作者Taylor,有说过,就是因为每个人对模型的理解不一样,对于放置的位置有各种意见,所以干脆就放在根目录下,把选择权交给大家;

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Laravel Eloquent ORM in Bangla partial model search) Laravel Eloquent ORM in Bangla partial model search) Apr 08, 2025 pm 02:06 PM

LaravelEloquent Model Retrieval: Easily obtaining database data EloquentORM provides a concise and easy-to-understand way to operate the database. This article will introduce various Eloquent model search techniques in detail to help you obtain data from the database efficiently. 1. Get all records. Use the all() method to get all records in the database table: useApp\Models\Post;$posts=Post::all(); This will return a collection. You can access data using foreach loop or other collection methods: foreach($postsas$post){echo$post->

The Future of PHP: Adaptations and Innovations The Future of PHP: Adaptations and Innovations Apr 11, 2025 am 12:01 AM

The future of PHP will be achieved by adapting to new technology trends and introducing innovative features: 1) Adapting to cloud computing, containerization and microservice architectures, supporting Docker and Kubernetes; 2) introducing JIT compilers and enumeration types to improve performance and data processing efficiency; 3) Continuously optimize performance and promote best practices.

PHP and Python: Comparing Two Popular Programming Languages PHP and Python: Comparing Two Popular Programming Languages Apr 14, 2025 am 12:13 AM

PHP and Python each have their own advantages, and choose according to project requirements. 1.PHP is suitable for web development, especially for rapid development and maintenance of websites. 2. Python is suitable for data science, machine learning and artificial intelligence, with concise syntax and suitable for beginners.

PHP vs. Python: Understanding the Differences PHP vs. Python: Understanding the Differences Apr 11, 2025 am 12:15 AM

PHP and Python each have their own advantages, and the choice should be based on project requirements. 1.PHP is suitable for web development, with simple syntax and high execution efficiency. 2. Python is suitable for data science and machine learning, with concise syntax and rich libraries.

PHP's Current Status: A Look at Web Development Trends PHP's Current Status: A Look at Web Development Trends Apr 13, 2025 am 12:20 AM

PHP remains important in modern web development, especially in content management and e-commerce platforms. 1) PHP has a rich ecosystem and strong framework support, such as Laravel and Symfony. 2) Performance optimization can be achieved through OPcache and Nginx. 3) PHP8.0 introduces JIT compiler to improve performance. 4) Cloud-native applications are deployed through Docker and Kubernetes to improve flexibility and scalability.

PHP: The Foundation of Many Websites PHP: The Foundation of Many Websites Apr 13, 2025 am 12:07 AM

The reasons why PHP is the preferred technology stack for many websites include its ease of use, strong community support, and widespread use. 1) Easy to learn and use, suitable for beginners. 2) Have a huge developer community and rich resources. 3) Widely used in WordPress, Drupal and other platforms. 4) Integrate tightly with web servers to simplify development deployment.

Laravel and the Backend: Powering Web Application Logic Laravel and the Backend: Powering Web Application Logic Apr 11, 2025 am 11:29 AM

How does Laravel play a role in backend logic? It simplifies and enhances backend development through routing systems, EloquentORM, authentication and authorization, event and listeners, and performance optimization. 1. The routing system allows the definition of URL structure and request processing logic. 2.EloquentORM simplifies database interaction. 3. The authentication and authorization system is convenient for user management. 4. The event and listener implement loosely coupled code structure. 5. Performance optimization improves application efficiency through caching and queueing.

PHP: A Key Language for Web Development PHP: A Key Language for Web Development Apr 13, 2025 am 12:08 AM

PHP is a scripting language widely used on the server side, especially suitable for web development. 1.PHP can embed HTML, process HTTP requests and responses, and supports a variety of databases. 2.PHP is used to generate dynamic web content, process form data, access databases, etc., with strong community support and open source resources. 3. PHP is an interpreted language, and the execution process includes lexical analysis, grammatical analysis, compilation and execution. 4.PHP can be combined with MySQL for advanced applications such as user registration systems. 5. When debugging PHP, you can use functions such as error_reporting() and var_dump(). 6. Optimize PHP code to use caching mechanisms, optimize database queries and use built-in functions. 7

See all articles