App\Repositories\Setting\EloquentSetting::byType PHP 메소드

byType() 공개 메소드

Get a model by setting type. If a model does not exist, create a new model.
public byType ( $type ) : Model
리턴 Illuminate\Database\Eloquent\Model
    public function byType($type)
    {
        $setting = $this->model->where('type', $type)->first();
        if (!is_null($setting)) {
            return $setting;
        }
        if ($type === 'mail') {
            $attributes = new MailSettingEntity();
            $attributes->setDriver('smtp');
            $attributes->setFrom(['address' => '[email protected]', 'name' => 'Webloyer']);
            $attributes->setSmtpHost('smtp.mailgun.org');
            $attributes->setSmtpPort(587);
            $attributes->setSmtpEncryption('tls');
            $attributes->setSendmailPath('/usr/sbin/sendmail -bs');
        }
        return $this->model->create(['type' => $type, 'attributes' => $attributes]);
    }