* @property string $content
* @property string $slug
* @property string $name
+ * @property string $filter_attribute // if set, $user->{$filter_attribute} has to be TRUE for email to be sent
* @property boolean $show_in_actions
*/
class EmailTemplate extends Model
/**
* @param string|EmailTemplate $template
+ * @return bool
*/
public function sendEmailFromTemplate($template)
{
$template = EmailTemplate::findSlug($template);
}
+ if($this->__get($template->filter_attribute) === false) {
+ return false;
+ }
+
\Mail::to($this)->send($template->getMailableFor($this));
+ return true;
}
/**
* @param $subject
* @param $content
* @todo Broken
+ * @deprecated
* Fills subject and content, then sends mail
*/
public function sendTemplateEmail($subject, $content)
*/
public function scopeIncompleteProfiles(Builder $builder): void
{
- $builder->whereNull($this->profileFilledAttributes, 'or');
+ $builder->where(fn(Builder $builder) => $builder->whereNull($this->profileFilledAttributes, 'or'));
}
/**
*/
public function getProfileFilledAttribute(): bool
{
- return !in_array(null, $this->only($this->profileFilledAttributes));
+ return ! $this->getProfileIncompleteAttribute();
+ }
+
+ /**
+ * @return bool
+ * Returns true if one $profileFilledAttributes is not filled
+ */
+ public function getProfileIncompleteAttribute(): bool
+ {
+ return in_array(null, $this->only($this->profileFilledAttributes));
}
/**
--- /dev/null
+<?php
+
+use Illuminate\Database\Migrations\Migration;
+use Illuminate\Database\Schema\Blueprint;
+use Illuminate\Support\Facades\Schema;
+
+class AddScopeToEmailTemplates extends Migration
+{
+ /**
+ * Run the migrations.
+ *
+ * @return void
+ */
+ public function up()
+ {
+ Schema::table('email_templates', function (Blueprint $table) {
+ $table->string('filter_attribute')->nullable();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table('email_templates', function (Blueprint $table) {
+ $table->dropColumn('filter_attribute');
+ });
+ }
+}