add more controllers and fix tests
This commit is contained in:
+22
-5
@@ -8,9 +8,13 @@ use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasApiTokens;
|
||||
|
||||
protected $table = 'users';
|
||||
|
||||
protected $fillable = [
|
||||
@@ -68,10 +72,23 @@ class User extends Authenticatable
|
||||
{
|
||||
// If user_roles has soft-deletes (deleted_at), filter it out.
|
||||
// If it does not, you can remove wherePivotNull('deleted_at').
|
||||
return $this->belongsToMany(Role::class, 'user_roles', 'user_id', 'role_id')
|
||||
->withTimestamps()
|
||||
->withPivot(['deleted_at', 'school_year'])
|
||||
->wherePivotNull('deleted_at');
|
||||
$relation = $this->belongsToMany(Role::class, 'user_roles', 'user_id', 'role_id')
|
||||
->withTimestamps();
|
||||
|
||||
$pivotColumns = [];
|
||||
if (Schema::hasColumn('user_roles', 'deleted_at')) {
|
||||
$pivotColumns[] = 'deleted_at';
|
||||
$relation->wherePivotNull('deleted_at');
|
||||
}
|
||||
if (Schema::hasColumn('user_roles', 'school_year')) {
|
||||
$pivotColumns[] = 'school_year';
|
||||
}
|
||||
|
||||
if (!empty($pivotColumns)) {
|
||||
$relation->withPivot($pivotColumns);
|
||||
}
|
||||
|
||||
return $relation;
|
||||
}
|
||||
|
||||
public function teacherClasses(): HasMany
|
||||
@@ -604,4 +621,4 @@ class User extends Authenticatable
|
||||
? $value
|
||||
: Hash::make($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user