The table structure is as follows:
表名:projects字段:id, name表名:projects_services(1 project_id <-> M service_id)字段:project_id, service_id表名:services字段:id, name表名:services_modules(M service_id <-> N module_id)字段:service_id, module_id表名:modules字段:id, name表名:modules_scripts(1 module_id<->1 script_id)字段:module_id, script_id表名:scripts字段:id, name
If I want to use Laravel's eloquent query the following information, how should it be implemented?
script_id, Script_name, Module_name, service_name, project_name
Reply content:
The table structure is as follows:
表名:projects字段:id, name表名:projects_services(1 project_id <-> M service_id)字段:project_id, service_id表名:services字段:id, name表名:services_modules(M service_id <-> N module_id)字段:service_id, module_id表名:modules字段:id, name表名:modules_scripts(1 module_id<->1 script_id)字段:module_id, script_id表名:scripts字段:id, name
If I want to use Laravel's eloquent query the following information, how should it be implemented?
script_id, Script_name, Module_name, service_name, project_name
Can be achieved, and laravel will achieve very elegant, you are here
projects->project_services->services->services_modules->modules->modules_scripts->scriputs
, seven table joint query, you first want to create these seven models, and to define the respective relationships, and then: $list =Projects::with('project_services.services.services_modules.modules.modules_scripts.scripts')->where('写上你的条件')-first(); 只需要这么简短的一句代码,就可以实现你的需求,就能非常方便的获取你所要的数据 project_name:$list->name, service_name:$list->project_services->services->name; module_name:$list->project_services->services->services_modules->modules->name; sript_name:$list->project_services->services->services_modules->modules->modules_scripts->scripts->name; sript_id:$list->project_services->services->services_modules->modules->modules_scripts->scripts->id;
This method I use more, very convenient, but like such a long connection query, I have not used.
The first floor has been said to be good
First define the relationships of these tables in Laravel eloquent, document address: Http://laravel.com/docs/5.1/eloquent-relationships
You can then use the Projects::with (...) directly in the controller. The content you need) is ready.