mardi 12 février 2019

Laravel model properties

I'm not sure how to best ask the question. I'm trying to write DRY code and I've got a Job model. A job can have types (ex: full-time, part-time, etc). If I want to only define the types once where would I put them that I could use them everywhere? Is the best way to do this something like:

class Job extends Model
{
    private static $jobTypes = [
        'full-time',
        'part-time',
    ];

    public static function jobTypes()
    {
        return self::$jobTypes;
    }
}

Or does doing a completely separate class make more sense / increase flexibility?

class JobTypes
{
    private static $jobTypes = [
        'full-time',
        'part-time',
    ];

    public static function jobTypes()
    {
        return self::$jobTypes;
    }
}

Or something else...



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire