loan order permissions
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace App\Models\Branch;
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Spatie\Translatable\HasTranslations;
|
||||
@@ -44,4 +45,12 @@ class Branch extends Model
|
||||
'name',
|
||||
'address',
|
||||
];
|
||||
|
||||
/**
|
||||
* Branches associated with user
|
||||
*/
|
||||
public function users(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(User::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,7 +3,11 @@
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use App\Models\Branch\Branch;
|
||||
use App\Models\Order\Loan\LoanOrder;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
@@ -47,7 +51,23 @@ class User extends Authenticatable
|
||||
];
|
||||
|
||||
/**
|
||||
* User is me?
|
||||
* Branches associated with user
|
||||
*/
|
||||
public function branches(): BelongsToMany
|
||||
{
|
||||
return $this->belongsToMany(Branch::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Loan orders user created
|
||||
*/
|
||||
public function loanOrders(): HasMany
|
||||
{
|
||||
return $this->hasMany(LoanOrder::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user is me.
|
||||
*/
|
||||
public function isMe(): bool
|
||||
{
|
||||
@@ -55,7 +75,7 @@ class User extends Authenticatable
|
||||
}
|
||||
|
||||
/**
|
||||
* Is user admin?
|
||||
* Check if user is admin.
|
||||
*/
|
||||
public function isAdmin(): bool
|
||||
{
|
||||
@@ -65,4 +85,20 @@ class User extends Authenticatable
|
||||
|
||||
return $this->hasRole(['king', 'superadmin', 'admin']);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user is operator.
|
||||
*/
|
||||
public function isOperator(): bool
|
||||
{
|
||||
return $this->hasRole('operator');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user owns loan order.
|
||||
*/
|
||||
public function ownsLoanOrder(LoanOrder $loanOrder): bool
|
||||
{
|
||||
return $this->id === $loanOrder->user_id;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user