guarded instead of fillable

This commit is contained in:
Benjamin Takats
2022-12-01 16:01:24 +01:00
parent 37695943ef
commit e3af9cf67d
37 changed files with 120 additions and 197 deletions

View File

@@ -4,31 +4,40 @@ namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Spatie\Sluggable\HasSlug;
use Spatie\Sluggable\SlugOptions;
class City extends Model
{
use HasFactory;
use HasSlug;
/**
* The attributes that are mass assignable.
*
* The attributes that aren't mass assignable.
* @var array
*/
protected $fillable = [
'country_id',
'name',
];
protected $guarded = [];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'id' => 'integer',
'id' => 'integer',
'country_id' => 'integer',
];
/**
* Get the options for generating the slug.
*/
public function getSlugOptions(): SlugOptions
{
return SlugOptions::create()
->generateSlugsFrom('name')
->saveSlugsTo('slug')
->usingLanguage('de');
}
public function country(): \Illuminate\Database\Eloquent\Relations\BelongsTo
{
return $this->belongsTo(Country::class);