relationships and roles
This commit is contained in:
@@ -26,4 +26,8 @@ class EsiToken extends Model
|
||||
'refresh_token',
|
||||
'expires_in',
|
||||
];
|
||||
|
||||
public function esiscopes() {
|
||||
return $this->hasMany('App\Models\EsiScope');
|
||||
}
|
||||
}
|
||||
|
||||
+11
-5
@@ -6,6 +6,8 @@ use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
|
||||
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use Notifiable;
|
||||
@@ -46,7 +48,15 @@ class User extends Authenticatable
|
||||
//Used in middleware to make sure a user is able to access many of the pages
|
||||
public function hasRole($role)
|
||||
{
|
||||
|
||||
$charId = User::where('character_id')->get();
|
||||
$checks = DB::table('user_roles')->where('character_id', $charId)->get();
|
||||
foreach($checks as $check) {
|
||||
if($check['role'] == $role) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
//return User::where('role', $role)->get();
|
||||
}
|
||||
|
||||
@@ -58,10 +68,6 @@ class User extends Authenticatable
|
||||
return $this->hasMany('App\Models\UserRole');
|
||||
}
|
||||
|
||||
public function esiscopes() {
|
||||
return $this->hasMany('App\Models\EsiScope');
|
||||
}
|
||||
|
||||
public function esitoken() {
|
||||
return $this->hasOne('App\Models\EsiToken');
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ class CreateUserRolesTable extends Migration
|
||||
$table->increments('id');
|
||||
$table->integer('character_id');
|
||||
$table->string('role')->default('None');
|
||||
$table->foreign('character_id')->references('character_id')->on('users');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@ class CreateEsiScopes extends Migration
|
||||
Schema::create('EsiScopes', function(Blueprint $table) {
|
||||
$table->increments('id');
|
||||
$table->integer('character_id');
|
||||
$table->foreign('character_id')->references('character_id')->on('EsiToken');
|
||||
$table->string('scope');
|
||||
$table->timestamps();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user