Agrego archivos iniciales
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
|
||||
class Jugador extends Model
|
||||
{
|
||||
use SoftDeletes;
|
||||
protected $table = 'jugadores';
|
||||
protected $primaryKey = 'id_jugador';
|
||||
public $timestamps = true;
|
||||
public $incrementing = false;
|
||||
|
||||
protected $fillable = [
|
||||
'id_jugador',
|
||||
'documento',
|
||||
'nombre',
|
||||
'apellido',
|
||||
'fecha_nacimiento',
|
||||
'edad',
|
||||
'categoria',
|
||||
'id_club_actual',
|
||||
'id_club_origen',
|
||||
'activo',
|
||||
'email',
|
||||
'telefono',
|
||||
'password',
|
||||
'reset_token',
|
||||
'reset_expira',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'reset_token',
|
||||
];
|
||||
|
||||
protected $casts = [
|
||||
'id_jugador' => 'string',
|
||||
'fecha_nacimiento' => 'date',
|
||||
'edad' => 'integer',
|
||||
'id_club_actual' => 'integer',
|
||||
'id_club_origen' => 'integer',
|
||||
'activo' => 'boolean',
|
||||
'reset_expira' => 'datetime',
|
||||
];
|
||||
|
||||
public function getCategoriaCalculadaAttribute()
|
||||
{
|
||||
if (!$this->fecha_nacimiento) return 'Sin categoría';
|
||||
|
||||
// Calculate age for the current year. (Categoría U15 is for players turning 14 and 15 in the current year).
|
||||
// That means current_year - birth_year
|
||||
$edadCategoria = date('Y') - $this->fecha_nacimiento->format('Y');
|
||||
|
||||
$categoria = Categoria::where('edad_min', '<=', $edadCategoria)
|
||||
->where('edad_max', '>=', $edadCategoria)
|
||||
->first();
|
||||
|
||||
return $categoria ? $categoria->nombre : 'Sin categoría';
|
||||
}
|
||||
|
||||
public function clubActual()
|
||||
{
|
||||
return $this->belongsTo(Club::class, 'id_club_actual', 'id_club');
|
||||
}
|
||||
|
||||
public function clubOrigen()
|
||||
{
|
||||
return $this->belongsTo(Club::class, 'id_club_origen', 'id_club');
|
||||
}
|
||||
|
||||
public function equipos()
|
||||
{
|
||||
return $this->belongsToMany(Equipo::class, 'jugador_equipo', 'id_jugador', 'id_equipo')
|
||||
->withPivot('fecha_alta');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user