You can't use the fixed keywords as your class names and all..try some other names rather than naming them same as library defined names.
No, I don't think it have to be plural, make it as simple as possible and singular.
May Sale! All accounts are 40% off this week.
i use phpstorm as an IDE. i have a model named class that contains information about classes as in school classes. so i would think to use class as the name of the class. the IDE reports it as a possible error. before moving forward would it be an error?
// Class model
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Class extends Model
{
protected $table = 'classes';
/**
* Class belongs to program type.
* @return mixed
*/
public function programType()
{
return $this->belongsTo(ProgramType::class);
}
}
// Program Types model
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class ProgramType extends Model
{
protected $table = 'program_types';
public $timestamps = false;
/**
* Program type has many classes.
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function classes()
{
return $this->hasMany(Class::class);
}
}
i think i ran into something similar with a model called Event but it worked out alright.
if this doesn't work, should i use a different name - what name? or use the plural?
Well some words are reserved in some languages. For example since PHP7.0 you can can't have a class that's called String anymore. As far as I know Class is not one of them!
Reserved words: http://php.net/manual/en/reserved.other-reserved-words.php
Please or to participate in this conversation.