aboutsummaryrefslogtreecommitdiffhomepage
path: root/main/app/sprinkles/extend-user/src/Database/Scopes/MemberAuxScope.php
diff options
context:
space:
mode:
Diffstat (limited to 'main/app/sprinkles/extend-user/src/Database/Scopes/MemberAuxScope.php')
-rwxr-xr-xmain/app/sprinkles/extend-user/src/Database/Scopes/MemberAuxScope.php36
1 files changed, 36 insertions, 0 deletions
diff --git a/main/app/sprinkles/extend-user/src/Database/Scopes/MemberAuxScope.php b/main/app/sprinkles/extend-user/src/Database/Scopes/MemberAuxScope.php
new file mode 100755
index 0000000..c732147
--- /dev/null
+++ b/main/app/sprinkles/extend-user/src/Database/Scopes/MemberAuxScope.php
@@ -0,0 +1,36 @@
+<?php
+
+namespace UserFrosting\Sprinkle\ExtendUser\Database\Scopes;
+
+use Illuminate\Database\Eloquent\Scope;
+use Illuminate\Database\Eloquent\Model;
+use Illuminate\Database\Eloquent\Builder;
+
+class MemberAuxScope implements Scope
+{
+ /**
+ * Apply the scope to a given Eloquent query builder.
+ *
+ * @param \Illuminate\Database\Eloquent\Builder $builder
+ * @param \Illuminate\Database\Eloquent\Model $model
+ * @return void
+ */
+ public function apply(Builder $builder, Model $model)
+ {
+ $baseTable = $model->getTable();
+ // Hardcode the table name here, or you can access it using the classMapper and `getTable`
+ $auxTable = 'members';
+
+ // Specify columns to load from base table and aux table
+ $builder->addSelect(
+ "$baseTable.*",
+ "$auxTable.city as city",
+ "$auxTable.country as country"
+ );
+
+ // Join on matching `member` records
+ $builder->leftJoin($auxTable, function ($join) use ($baseTable, $auxTable) {
+ $join->on("$auxTable.id", '=', "$baseTable.id");
+ });
+ }
+}