guarded instead of fillable

This commit is contained in:
Benjamin Takats
2022-12-01 16:01:24 +01:00
parent 4699805e60
commit 470e9c68b8
37 changed files with 120 additions and 197 deletions

View File

@@ -10,14 +10,11 @@ class Category extends Model
use HasFactory;
/**
* The attributes that are mass assignable.
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'slug',
];
protected $guarded = [];
/**
* The attributes that should be cast to native types.

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);

View File

@@ -10,14 +10,11 @@ class Country extends Model
use HasFactory;
/**
* The attributes that are mass assignable.
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $fillable = [
'name',
'code',
];
protected $guarded = [];
/**
* The attributes that should be cast to native types.

View File

@@ -10,14 +10,11 @@ class Course extends Model
use HasFactory;
/**
* The attributes that are mass assignable.
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $fillable = [
'lecturer_id',
'name',
];
protected $guarded = [];
/**
* The attributes that should be cast to native types.

View File

@@ -10,16 +10,11 @@ class Event extends Model
use HasFactory;
/**
* The attributes that are mass assignable.
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $fillable = [
'course_id',
'venue_id',
'from',
'to',
];
protected $guarded = [];
/**
* The attributes that should be cast to native types.

View File

@@ -10,16 +10,11 @@ class Lecturer extends Model
use HasFactory;
/**
* The attributes that are mass assignable.
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $fillable = [
'team_id',
'name',
'slug',
'active',
];
protected $guarded = [];
/**
* The attributes that should be cast to native types.

View File

@@ -10,14 +10,11 @@ class Participant extends Model
use HasFactory;
/**
* The attributes that are mass assignable.
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $fillable = [
'first_name',
'last_name',
];
protected $guarded = [];
/**
* The attributes that should be cast to native types.

View File

@@ -10,15 +10,11 @@ class Registration extends Model
use HasFactory;
/**
* The attributes that are mass assignable.
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $fillable = [
'event_id',
'participant_id',
'active',
];
protected $guarded = [];
/**
* The attributes that should be cast to native types.

View File

@@ -10,16 +10,11 @@ class Venue extends Model
use HasFactory;
/**
* The attributes that are mass assignable.
* The attributes that aren't mass assignable.
*
* @var array
*/
protected $fillable = [
'city_id',
'name',
'slug',
'street',
];
protected $guarded = [];
/**
* The attributes that should be cast to native types.

View File

@@ -9,8 +9,6 @@ use Laravel\Nova\Fields\BelongsToMany;
class Category extends Resource
{
/**
* The model the resource corresponds to.
*
@@ -34,11 +32,6 @@ class Category extends Resource
'id',
];
public static function label()
{
return __('Categories');
}
/**
* Get the fields displayed by the resource.
*

View File

@@ -2,52 +2,53 @@
namespace App\Nova;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\BelongsTo;
use Laravel\Nova\Fields\ID;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\BelongsTo;
class City extends Resource
{
/**
* The model the resource corresponds to.
*
* @var string
*/
public static $model = \App\Models\City::class;
/**
* The single value that should be used to represent the resource when being displayed.
*
* @var string
*/
public static $title = 'id';
/**
* The columns that should be searched.
*
* @var array
*/
public static $search = [
'id',
];
public static function label()
{
return __('Cities');
}
/**
* Get the fields displayed by the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function fields(Request $request)
{
return [
ID::make()
->sortable(),
ID::make()->sortable(),
Text::make('Name')
->rules('required', 'string'),
Text::make('Slug')
->rules('required', 'string', 'unique:cities,slug'),
BelongsTo::make('Country'),
@@ -58,7 +59,6 @@ class City extends Resource
* Get the cards available for the request.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function cards(Request $request)
@@ -70,7 +70,6 @@ class City extends Resource
* Get the filters available for the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function filters(Request $request)
@@ -82,7 +81,6 @@ class City extends Resource
* Get the lenses available for the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function lenses(Request $request)
@@ -94,7 +92,6 @@ class City extends Resource
* Get the actions available for the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function actions(Request $request)

View File

@@ -9,8 +9,6 @@ use Laravel\Nova\Fields\HasMany;
class Country extends Resource
{
/**
* The model the resource corresponds to.
*
@@ -34,11 +32,6 @@ class Country extends Resource
'id',
];
public static function label()
{
return __('Countries');
}
/**
* Get the fields displayed by the resource.
*

View File

@@ -10,8 +10,6 @@ use Laravel\Nova\Fields\BelongsToMany;
class Course extends Resource
{
/**
* The model the resource corresponds to.
*
@@ -35,11 +33,6 @@ class Course extends Resource
'id',
];
public static function label()
{
return __('Courses');
}
/**
* Get the fields displayed by the resource.
*

View File

@@ -9,8 +9,6 @@ use Laravel\Nova\Fields\BelongsTo;
class Event extends Resource
{
/**
* The model the resource corresponds to.
*
@@ -34,11 +32,6 @@ class Event extends Resource
'id',
];
public static function label()
{
return __('Events');
}
/**
* Get the fields displayed by the resource.
*

View File

@@ -10,8 +10,6 @@ use Laravel\Nova\Fields\BelongsTo;
class Lecturer extends Resource
{
/**
* The model the resource corresponds to.
*
@@ -35,11 +33,6 @@ class Lecturer extends Resource
'id',
];
public static function label()
{
return __('Lecturers');
}
/**
* Get the fields displayed by the resource.
*

View File

@@ -8,8 +8,6 @@ use Laravel\Nova\Fields\Text;
class Participant extends Resource
{
/**
* The model the resource corresponds to.
*
@@ -33,11 +31,6 @@ class Participant extends Resource
'id',
];
public static function label()
{
return __('Participants');
}
/**
* Get the fields displayed by the resource.
*

View File

@@ -9,8 +9,6 @@ use Laravel\Nova\Fields\BelongsTo;
class Registration extends Resource
{
/**
* The model the resource corresponds to.
*
@@ -34,11 +32,6 @@ class Registration extends Resource
'id',
];
public static function label()
{
return __('Registrations');
}
/**
* Get the fields displayed by the resource.
*

View File

@@ -9,8 +9,6 @@ use Laravel\Nova\Fields\BelongsTo;
class Venue extends Resource
{
/**
* The model the resource corresponds to.
*
@@ -34,11 +32,6 @@ class Venue extends Resource
'id',
];
public static function label()
{
return __('Venues');
}
/**
* Get the fields displayed by the resource.
*

View File

@@ -14,6 +14,7 @@ class TeamPolicy
* Determine whether the user can view any models.
*
* @param \App\Models\User $user
*
* @return mixed
*/
public function viewAny(User $user)
@@ -26,6 +27,7 @@ class TeamPolicy
*
* @param \App\Models\User $user
* @param \App\Models\Team $team
*
* @return mixed
*/
public function view(User $user, Team $team)
@@ -37,11 +39,12 @@ class TeamPolicy
* Determine whether the user can create models.
*
* @param \App\Models\User $user
*
* @return mixed
*/
public function create(User $user)
{
return true;
return false;
}
/**
@@ -49,6 +52,7 @@ class TeamPolicy
*
* @param \App\Models\User $user
* @param \App\Models\Team $team
*
* @return mixed
*/
public function update(User $user, Team $team)
@@ -61,6 +65,7 @@ class TeamPolicy
*
* @param \App\Models\User $user
* @param \App\Models\Team $team
*
* @return mixed
*/
public function addTeamMember(User $user, Team $team)
@@ -73,6 +78,7 @@ class TeamPolicy
*
* @param \App\Models\User $user
* @param \App\Models\Team $team
*
* @return mixed
*/
public function updateTeamMember(User $user, Team $team)
@@ -85,6 +91,7 @@ class TeamPolicy
*
* @param \App\Models\User $user
* @param \App\Models\Team $team
*
* @return mixed
*/
public function removeTeamMember(User $user, Team $team)
@@ -97,10 +104,12 @@ class TeamPolicy
*
* @param \App\Models\User $user
* @param \App\Models\Team $team
*
* @return mixed
*/
public function delete(User $user, Team $team)
{
return $user->ownsTeam($team);
// return $user->ownsTeam($team);
return false;
}
}