add more controllers and fix tests
This commit is contained in:
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\BaseModel;
|
||||
|
||||
class Supply extends BaseModel
|
||||
{
|
||||
protected $table = 'supplies';
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'unit',
|
||||
'qty_on_hand',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'qty_on_hand' => 'integer',
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use App\Models\BaseModel;
|
||||
|
||||
class SupplyTransaction extends BaseModel
|
||||
{
|
||||
protected $table = 'supply_transactions';
|
||||
|
||||
protected $fillable = [
|
||||
'supply_id',
|
||||
'type',
|
||||
'quantity',
|
||||
'ref',
|
||||
'issued_to',
|
||||
'issued_by',
|
||||
'notes',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'supply_id' => 'integer',
|
||||
'quantity' => 'integer',
|
||||
];
|
||||
}
|
||||
+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