|null $variables * @property bool $is_active * @property \Illuminate\Support\Carbon|null $created_at * @property \Illuminate\Support\Carbon|null $updated_at * @property \Illuminate\Support\Carbon|null $deleted_at * @method static \Database\Factories\NotificationTemplateFactory factory($count = null, $state = []) * @method static \Illuminate\Database\Eloquent\Builder|NotificationTemplate newModelQuery() * @method static \Illuminate\Database\Eloquent\Builder|NotificationTemplate newQuery() * @method static \Illuminate\Database\Eloquent\Builder|NotificationTemplate onlyTrashed() * @method static \Illuminate\Database\Eloquent\Builder|NotificationTemplate query() * @method static \Illuminate\Database\Eloquent\Builder|NotificationTemplate whereBody($value) * @method static \Illuminate\Database\Eloquent\Builder|NotificationTemplate whereCreatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|NotificationTemplate whereDeletedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|NotificationTemplate whereId($value) * @method static \Illuminate\Database\Eloquent\Builder|NotificationTemplate whereIdentifier($value) * @method static \Illuminate\Database\Eloquent\Builder|NotificationTemplate whereIsActive($value) * @method static \Illuminate\Database\Eloquent\Builder|NotificationTemplate whereName($value) * @method static \Illuminate\Database\Eloquent\Builder|NotificationTemplate whereSubject($value) * @method static \Illuminate\Database\Eloquent\Builder|NotificationTemplate whereUpdatedAt($value) * @method static \Illuminate\Database\Eloquent\Builder|NotificationTemplate whereVariables($value) * @method static \Illuminate\Database\Eloquent\Builder|NotificationTemplate withTrashed(bool $withTrashed = true) * @method static \Illuminate\Database\Eloquent\Builder|NotificationTemplate withoutTrashed() * @mixin \Eloquent */ class NotificationTemplate extends Model { use HasFactory, SoftDeletes; protected $fillable = [ 'identifier', 'name', 'subject', 'body', 'variables', 'is_active', ]; /** * @return array */ protected function casts(): array { return [ 'variables' => 'array', 'is_active' => 'boolean', ]; } public static function getAttributeLabel(string $attribute): string { return __('notification_templates.fields.'.$attribute); } public static function findByIdentifier(string $identifier): ?self { return self::query() ->where('identifier', $identifier) ->where('is_active', true) ->first(); } public function renderSubject(array $vars): string { return $this->replacePlaceholders($this->subject, $vars); } public function renderBody(array $vars): string { return $this->replacePlaceholders($this->body, $vars); } private function replacePlaceholders(string $text, array $vars): string { foreach ($vars as $key => $value) { $text = str_replace('{'.$key.'}', (string) $value, $text); } return $text; } }