This commit is contained in:
2021-05-24 23:11:29 +09:00
parent 58258a070e
commit af7c7344b4
3 changed files with 12 additions and 8 deletions

View File

@@ -39,7 +39,7 @@ class TestController extends Controller
$perms = new Collection; $perms = new Collection;
var_dump(auth()->user()->userAlts()); var_dump(auth()->user()->getAlts());
dd(auth()->user()->altCount()); dd(auth()->user()->altCount());
//Get all of the users in the database //Get all of the users in the database
@@ -49,9 +49,9 @@ class TestController extends Controller
//in this first part //in this first part
foreach($users as $char) { foreach($users as $char) {
$altCount = $char->altCount(); $altCount = $char->altCount();
dd($altCount);
if($altCount > 0) { if($altCount > 0) {
$alts = $char->userAlts; $alts = $char->getAlts();
foreach($alts as $alt) { foreach($alts as $alt) {
$perms->push([ $perms->push([

View File

@@ -63,12 +63,12 @@ class User extends Authenticatable
return $this->hasMany('App\Models\User\UserAlt', 'character_id', 'main_id'); return $this->hasMany('App\Models\User\UserAlt', 'character_id', 'main_id');
} }
public function getUserAlts() { public function altCount() {
return $this->hasMany('App\Models\User\UserAlt', 'character_id', 'main_id')->get(); return UserAlt::where(['main_id' => $this->character_id])->count();
} }
public function altCount() { public function getAlts() {
return $this->hasMany('App\Models\User\UserAlt', 'character_id', 'main_id')->count(); return UserAlt::where(['main_id' => $this->character_id])->get();
} }
public function hasPermission($permission) { public function hasPermission($permission) {

View File

@@ -32,6 +32,10 @@ class UserAlt extends Model
]; ];
public function mainCharacter() { public function mainCharacter() {
return $this->belongsTo('App\Models\User\User', 'character_id'); return $this->belongsTo('App\Models\User\User', 'character_id', 'main_id');
}
public function getMain() {
return User::where(['character_id' => $this->main_id])->get();
} }
} }