从同一表获取不同的数据
我有一个名为用户的表。我已经将用户和专营权存储在同一张表中。在存储用户时,我也在与该行的同一张表中存储了特许经营ID。因此,如何获取特许经营信息以及用户信息... ???
return $data= DB::table('users')
->join('tbl_customergroups', 'tbl_customergroups.customergroup_id', 'users.group_id')
->where('users.user_type', 2)
->where('users.id', 'users.franchise_id')
->where('users.status', 0)
->orWhere('users.user_type', 5)
->select('tbl_customergroups.*', 'users.*')
->latest('users.created_at')
->paginate(10);
用户的表模式:
$table->string('franchise_id')->nullable();
$table->string('user_id')->nullable();
$table->string('date_of_join')->nullable();
$table->string('franchise_id')->nullable();
$table->string('name')->nullable();
$table->string('email')->unique(); ```
I have a table named users. I have stored users and the franchise in the same table. and while storing users I have stored franchise id as well in that same table with the row. so how can I fetch franchise information along with the user information...???
return $data= DB::table('users')
->join('tbl_customergroups', 'tbl_customergroups.customergroup_id', 'users.group_id')
->where('users.user_type', 2)
->where('users.id', 'users.franchise_id')
->where('users.status', 0)
->orWhere('users.user_type', 5)
->select('tbl_customergroups.*', 'users.*')
->latest('users.created_at')
->paginate(10);
User's table schema :
$table->string('franchise_id')->nullable();
$table->string('user_id')->nullable();
$table->string('date_of_join')->nullable();
$table->string('franchise_id')->nullable();
$table->string('name')->nullable();
$table->string('email')->unique(); ```
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您想要雄辩解决方案,我假设用户模型与特许经营模型之间存在关系,这可能是一个可能的解决方案:
您的用户模型应该具有像这:
在您的控制器中,您必须使用这样的用户模型来获取专营权:
If you want Eloquent solutions, and I am assuming that there is a relation between the users model and the franchise model, this could be a possible solution:
Your User model should have a function like this:
In your controller you have to fetch the franchise using a user model like this: