From ff4e7764d5f6dbee6739c20ae91b82172a1d6e8f Mon Sep 17 00:00:00 2001 From: jack Date: Sat, 26 May 2018 09:37:56 +0800 Subject: [PATCH] added relationship for company and user --- app/Company.php | 5 +++++ app/Http/Controllers/AuthController.php | 3 +++ app/User.php | 5 +++++ 3 files changed, 13 insertions(+) diff --git a/app/Company.php b/app/Company.php index af4bf8d..ee6bb6c 100644 --- a/app/Company.php +++ b/app/Company.php @@ -9,4 +9,9 @@ class Company extends Model // protected $fillable = ['company_profile', 'reg_cert', 'company_name', 'registration_no', 'tax_no', 'tel_no', 'fax', 'address', 'city', 'postcode', 'state', 'country', 'contact_person']; //protected $guarded = []; + + public function user() + { + return $this->belongsTo('App\User'); + } } diff --git a/app/Http/Controllers/AuthController.php b/app/Http/Controllers/AuthController.php index 48d0639..2707ce1 100644 --- a/app/Http/Controllers/AuthController.php +++ b/app/Http/Controllers/AuthController.php @@ -99,6 +99,9 @@ class AuthController extends Controller if (!$userToken=JWTAuth::fromUser($check_user)) { return response()->json(['error' => 'invalid_credentials'], 401); } + + // TODO : Create company for user + $expiration = JWTAuth::setToken($userToken)->getPayload()->get('exp'); // all good so return the token diff --git a/app/User.php b/app/User.php index e82ca32..a5bb95e 100644 --- a/app/User.php +++ b/app/User.php @@ -54,4 +54,9 @@ class User extends Authenticatable implements JWTSubject return $this->hasOne('App\UserVerification', 'user_id'); } + public function company() + { + return $this->hasOne('App\Company'); + } + }