Initial commit: Horux Strategy Platform
- Laravel 11 backend with API REST - React 18 + TypeScript + Vite frontend - Multi-parser architecture for accounting systems (CONTPAQi, Aspel, SAP) - 27+ financial metrics calculation - PDF report generation with Browsershot - Complete documentation (10 documents) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
75
backend/app/Models/User.php
Normal file
75
backend/app/Models/User.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Laravel\Sanctum\HasApiTokens;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasApiTokens, HasFactory, Notifiable;
|
||||
|
||||
protected $fillable = [
|
||||
'nombre',
|
||||
'email',
|
||||
'password',
|
||||
'role',
|
||||
'cliente_id',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
||||
|
||||
public function cliente(): BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Cliente::class);
|
||||
}
|
||||
|
||||
public function permisosEmpleado(): HasMany
|
||||
{
|
||||
return $this->hasMany(PermisoEmpleado::class);
|
||||
}
|
||||
|
||||
public function isAdmin(): bool
|
||||
{
|
||||
return $this->role === 'admin';
|
||||
}
|
||||
|
||||
public function isAnalista(): bool
|
||||
{
|
||||
return $this->role === 'analista';
|
||||
}
|
||||
|
||||
public function isCliente(): bool
|
||||
{
|
||||
return $this->role === 'cliente';
|
||||
}
|
||||
|
||||
public function isEmpleado(): bool
|
||||
{
|
||||
return $this->role === 'empleado';
|
||||
}
|
||||
|
||||
public function canAccessCliente(int $clienteId): bool
|
||||
{
|
||||
if ($this->isAdmin() || $this->isAnalista()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->cliente_id === $clienteId;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user