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:
1st - user already logged in
2nd - in customer table which connect to user table in(customer_id=user_id) check if package for this user == 1
So I have 2 tables:
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. 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
@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
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.