initial commit
This commit is contained in:
commit
1e1aa7d461
215 changed files with 35140 additions and 0 deletions
86
app/Models/Character.php
Normal file
86
app/Models/Character.php
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Character extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'level',
|
||||
'race',
|
||||
'gender',
|
||||
'class'
|
||||
];
|
||||
|
||||
/**
|
||||
* Get the route key for the model.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getRouteKeyName()
|
||||
{
|
||||
return 'slug';
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the model for a bound value.
|
||||
*
|
||||
* @param mixed $value
|
||||
* @param string|null $field
|
||||
* @return \Illuminate\Database\Eloquent\Model|null
|
||||
*/
|
||||
public function resolveRouteBinding($value, $field = null)
|
||||
{
|
||||
return $this->slug($value)->firstOrFail();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the character's name.
|
||||
*
|
||||
* @param string $value
|
||||
* @return void
|
||||
*/
|
||||
public function setNameAttribute($value)
|
||||
{
|
||||
$this->attributes['name'] = Str::ucfirst($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the user that owns this character.
|
||||
*/
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo(User::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve the character's professions.
|
||||
*/
|
||||
public function professions()
|
||||
{
|
||||
return $this->hasMany(CharacterProfession::class);
|
||||
}
|
||||
|
||||
public function scopeSlug($q, $name)
|
||||
{
|
||||
return $q->where('name', Str::ucfirst($name));
|
||||
}
|
||||
|
||||
public function getSlugAttribute()
|
||||
{
|
||||
return Str::lower($this->name);
|
||||
}
|
||||
}
|
||||
Reference in a new issue