我有用户表。这些用户表具有 company_id 属性。
我有一些带有 id 的通用页面。
https://www.test.com/customer_question/p/4701/c/40960
仅当登录用户具有特定的 company_id 时才需要访问此 url。否则其他一些人可以通过增加 IDS 来访问链接
因此,在每个控制器(索引、存储、更新等)中,我必须检查类似这样的内容
$company_id = Auth::user()->company_id;
$verify_seller = DB::table('sellers')
->select('*')
->where('company_id', '=', $company_id)
->get();
if ($verify_seller->isEmpty())
return "This product neither belongs to your seller account nor another seller's product";
我想我可以通过将上面的代码放到每个客户的 _construct 函数中来处理这个问题。
用 Laravel 处理这种情况的最佳方法是什么?
Laravel 5.6 版