55 lines
1.1 KiB
PHP
55 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
class Articolo extends Model
|
|
{
|
|
protected $table = 'articoli';
|
|
|
|
protected $fillable = [
|
|
'codice_articolo',
|
|
'ciclo',
|
|
'diametro',
|
|
'descrizione',
|
|
'posizione',
|
|
'quantita',
|
|
'tipo_lavorazione',
|
|
'materiale_lavorare',
|
|
'maximum_thickness',
|
|
'speed_rpm',
|
|
'feed',
|
|
'max_thrust_a',
|
|
'min_torque_a',
|
|
'quantita_fori',
|
|
'qr_code',
|
|
];
|
|
|
|
protected $casts = [
|
|
'quantita' => 'integer',
|
|
'speed_rpm' => 'integer',
|
|
'feed' => 'decimal:2',
|
|
'quantita_fori' => 'integer',
|
|
];
|
|
|
|
protected static function boot()
|
|
{
|
|
parent::boot();
|
|
|
|
static::created(function ($articolo) {
|
|
if (empty($articolo->qr_code)) {
|
|
// Formato: id-timestamp (es: 42-1737235200)
|
|
$articolo->qr_code = $articolo->id . '-' . time();
|
|
$articolo->saveQuietly();
|
|
}
|
|
});
|
|
}
|
|
|
|
public function getQrUrlAttribute(): string
|
|
{
|
|
return $this->qr_code;
|
|
}
|
|
|
|
|
|
}
|