[英]laravel How to check record in table connect to users table
I'm new in laravel and maybe its strange question, I don't want any user to redirect to specific page if two conditions are not valid: 我是laravel的新手,也许是一个奇怪的问题,如果两个条件无效,我不希望任何用户重定向到特定页面:
1st - user already logged in 1st-用户已经登录
2nd - in customer table which connect to user table in(customer_id=user_id) check if package for this user == 1 第二-在连接到用户表中的客户表中(customer_id = user_id)检查此用户的软件包是否== 1
So I have 2 tables: 所以我有2张桌子:
one for users 一个给用户
user_id
user_email
user_password
and customer table 和客户表
customer_id
package number
If user logged in and if customer_id=current logged user id and package ==1, redirect. 如果用户已登录,并且customer_id =当前已记录的用户ID和package == 1,请重定向。 Hope any body can help me. 希望任何人都能帮助我。
I know how to check for the table users but how to check for the table customers for the same customer id 我知道如何检查表用户,但如何检查表客户是否具有相同的客户ID
@if(auth()->user()->user_id== 0)
try this: 尝试这个:
//use Auth Facade...
if (Auth::check() && Auth::user()->customer->package_number == 1) {
//redirect to destination
}else{
//redirect to error page
}
you could use this. 你可以用这个
In your User Model 在您的用户模型中
class User extends Model
{
//bunch of codes
public function customer()
{
return $this->hasOne('App\Customers', 'customer_id', 'user_id');
}
}
then in your condition 然后你的情况
if(Auth::attempt(array('user_email' => $email, 'user_password' => $pass), true)
&& Auth::user()->customer->package_number == 1){
//do some magic
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.