File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace UserFrosting \Sprinkle \ExtendUser \Database \Scopes ;
4+
5+ use Illuminate \Database \Eloquent \Scope ;
6+ use Illuminate \Database \Eloquent \Model ;
7+ use Illuminate \Database \Eloquent \Builder ;
8+
9+ class MemberAuxScope implements Scope
10+ {
11+ /**
12+ * Apply the scope to a given Eloquent query builder.
13+ *
14+ * @param \Illuminate\Database\Eloquent\Builder $builder
15+ * @param \Illuminate\Database\Eloquent\Model $model
16+ * @return void
17+ */
18+ public function apply (Builder $ builder , Model $ model )
19+ {
20+ $ baseTable = $ model ->getTable ();
21+ // Hardcode the table name here, or you can access it using the classMapper and `getTable`
22+ $ auxTable = 'members ' ;
23+
24+ // Specify columns to load from base table and aux table
25+ $ builder ->addSelect (
26+ "$ baseTable.* " ,
27+ "$ auxTable.city as city " ,
28+ "$ auxTable.country as country "
29+ );
30+
31+ // Join on matching `member` records
32+ $ builder ->leftJoin ($ auxTable , function ($ join ) use ($ baseTable , $ auxTable ) {
33+ $ join ->on ("$ auxTable.id " , '= ' , "$ baseTable.id " );
34+ });
35+ }
36+ }
You can’t perform that action at this time.
0 commit comments