first commit
This commit is contained in:
53
app/Models/Articolo.php
Normal file
53
app/Models/Articolo.php
Normal file
@@ -0,0 +1,53 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user