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);
|
||||
}
|
||||
}
|
||||
88
app/Models/CharacterProfession.php
Normal file
88
app/Models/CharacterProfession.php
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
class CharacterProfession extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'character_id',
|
||||
'profession_id',
|
||||
'skill',
|
||||
];
|
||||
|
||||
/**
|
||||
* The relationships that should always be loaded.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $with = [
|
||||
'profession'
|
||||
];
|
||||
|
||||
/**
|
||||
* The accessors to append to the model's array form.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $appends = [ 'name' ];
|
||||
|
||||
/**
|
||||
* Relation to the actual profession data.
|
||||
*/
|
||||
public function profession()
|
||||
{
|
||||
return $this->belongsTo(Profession::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the character that has this profession.
|
||||
*/
|
||||
public function character()
|
||||
{
|
||||
return $this->belongsTo(Character::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the character's recipes for this profession.
|
||||
*/
|
||||
public function recipes()
|
||||
{
|
||||
return $this->belongsToMany(Recipe::class,
|
||||
'character_profession_recipe', 'ch_prof_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Learn a recipe for this character and profession.
|
||||
*/
|
||||
public function learn(Recipe $recipe)
|
||||
{
|
||||
return $this->recipes()->save($recipe);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get profession name.
|
||||
*/
|
||||
public function getNameAttribute() : string
|
||||
{
|
||||
return $this->profession->name;
|
||||
}
|
||||
|
||||
public function getSlugAttribute() : string
|
||||
{
|
||||
return $this->profession->slug;
|
||||
}
|
||||
}
|
||||
47
app/Models/Item.php
Normal file
47
app/Models/Item.php
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Item extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'external_id',
|
||||
'texture',
|
||||
'color'
|
||||
];
|
||||
|
||||
protected static function boot() {
|
||||
parent::boot();
|
||||
|
||||
static::creating(function ($item) {
|
||||
$item->slug = Str::slug($item->name);
|
||||
});
|
||||
}
|
||||
|
||||
public function recipe()
|
||||
{
|
||||
return $this->belongsTo(Recipe::class, 'id');
|
||||
}
|
||||
|
||||
public function getQuantityAttribute()
|
||||
{
|
||||
if ($this->pivot) {
|
||||
return $this->pivot->quantity;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
62
app/Models/Profession.php
Normal file
62
app/Models/Profession.php
Normal file
|
|
@ -0,0 +1,62 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Profession extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* 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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all characters with this profession.
|
||||
*/
|
||||
public function characters()
|
||||
{
|
||||
return $this->belongsToMany(Character::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* What recipes this profession has
|
||||
*/
|
||||
public function recipes()
|
||||
{
|
||||
return $this->hasMany(Recipe::class);
|
||||
}
|
||||
|
||||
public function scopeSlug($q, $name)
|
||||
{
|
||||
return $q->where('name', Str::ucfirst($name));
|
||||
}
|
||||
|
||||
public function getSlugAttribute()
|
||||
{
|
||||
return Str::lower($this->name);
|
||||
}
|
||||
}
|
||||
131
app/Models/Recipe.php
Normal file
131
app/Models/Recipe.php
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Staudenmeir\EloquentHasManyDeep\HasRelationships as HasDeepRelation;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Recipe extends Model
|
||||
{
|
||||
use Traits\HasSlug;
|
||||
use HasDeepRelation;
|
||||
use HasFactory;
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* The relationships that should always be loaded.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $with = [
|
||||
'profession',
|
||||
'craft'
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'profession_id',
|
||||
'category_id',
|
||||
'item_id'
|
||||
];
|
||||
|
||||
/**
|
||||
* 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->whereHas('craft', function ($q) use ($value) {
|
||||
$q->where('slug', $value);
|
||||
})->firstOrFail();
|
||||
}
|
||||
|
||||
/**
|
||||
* What profession this item belongs to.
|
||||
*/
|
||||
public function profession()
|
||||
{
|
||||
return $this->belongsTo(Profession::class);
|
||||
}
|
||||
|
||||
/**
|
||||
* What category this recipe belongs to.
|
||||
*/
|
||||
public function category()
|
||||
{
|
||||
return $this->belongsTo(RecipeCategory::class, 'category_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* What item this recipe crafts.
|
||||
*/
|
||||
public function craft()
|
||||
{
|
||||
return $this->belongsTo(Item::class, 'item_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all character professions.
|
||||
*/
|
||||
public function character_profession()
|
||||
{
|
||||
return $this->belongsToMany(CharacterProfession::class,
|
||||
'character_profession_recipe', null, 'ch_prof_id');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all character that can craft this recipe.
|
||||
*/
|
||||
public function crafters()
|
||||
{
|
||||
return $this->hasManyDeep(Character::class,
|
||||
['character_profession_recipe', CharacterProfession::class],
|
||||
[ null, 'id', 'id'],
|
||||
[ null,'ch_prof_id', 'character_id']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* What reagents is needed to craft this recipe.
|
||||
*/
|
||||
public function reagents()
|
||||
{
|
||||
return $this->belongsToMany(Item::class, 'reagents')
|
||||
->withPivot('quantity');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get recipe name from crafted item.
|
||||
*/
|
||||
public function getNameAttribute()
|
||||
{
|
||||
return $this->craft->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get recipe slug from crafted item.
|
||||
*/
|
||||
public function getSlugAttribute()
|
||||
{
|
||||
return $this->craft->slug;
|
||||
}
|
||||
}
|
||||
27
app/Models/RecipeCategory.php
Normal file
27
app/Models/RecipeCategory.php
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class RecipeCategory extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public $timestamps = false;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
];
|
||||
|
||||
public function recipes()
|
||||
{
|
||||
return $this->hasMany(Recipe::class, 'category_id');
|
||||
}
|
||||
}
|
||||
18
app/Models/Traits/HasSlug.php
Normal file
18
app/Models/Traits/HasSlug.php
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models\Traits;
|
||||
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
trait HasSlug
|
||||
{
|
||||
public function setSlugAttribute($value)
|
||||
{
|
||||
$this->attributes['slug'] = Str::slug($value);
|
||||
}
|
||||
|
||||
public function scopeSlug($q, $value)
|
||||
{
|
||||
return $q->where('slug', Str::slug($value));
|
||||
}
|
||||
}
|
||||
48
app/Models/User.php
Normal file
48
app/Models/User.php
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasFactory, Notifiable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'username',
|
||||
'password',
|
||||
'role'
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for arrays.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
];
|
||||
|
||||
public function characters()
|
||||
{
|
||||
return $this->hasMany(Character::class);
|
||||
}
|
||||
}
|
||||
Reference in a new issue