- Added AuthController for client login and token management. - Introduced AuthGate for handling authentication state and login UI. - Updated API to support fetching client data for pre-filling forms. - Modified App.vue to pre-fill client information if logged in. - Enhanced client model to include username and password fields. - Created migration for adding username and password to clients table. - Added utility for generating secure usernames and passwords. - Updated frontend to handle client tokens for pre-filling checkout forms. - Removed old CSS file and updated HTML references to new assets. - Added StatsOverview widget for displaying client and quote statistics. - Improved error handling and user feedback in the login process.
45 lines
933 B
PHP
45 lines
933 B
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
|
use Laravel\Sanctum\HasApiTokens;
|
|
|
|
class Cliente extends Model
|
|
{
|
|
use HasApiTokens;
|
|
|
|
protected $table = 'clienti';
|
|
|
|
protected $fillable = [
|
|
'username', 'password',
|
|
'nome', 'cognome', 'ragione_sociale', 'email', 'telefono',
|
|
'indirizzo', 'cap', 'citta', 'provincia', 'note',
|
|
];
|
|
|
|
protected $hidden = [
|
|
'password',
|
|
];
|
|
|
|
protected $casts = [
|
|
'password' => 'hashed',
|
|
];
|
|
|
|
public function preventivi(): HasMany
|
|
{
|
|
return $this->hasMany(Preventivo::class);
|
|
}
|
|
|
|
public function getNominativoAttribute(): string
|
|
{
|
|
if ($this->ragione_sociale) {
|
|
return $this->ragione_sociale;
|
|
}
|
|
|
|
$nome = trim("{$this->nome} {$this->cognome}");
|
|
|
|
return $nome !== '' ? $nome : $this->username;
|
|
}
|
|
}
|