File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -220,6 +220,16 @@ class RecentOrdersView extends View
220220}
221221```
222222
223+ Additionally, you can start a query against the view using the ` query() ` method:
224+
225+ ``` php
226+ <?php
227+
228+ RecentOrdersView::query()
229+ ->where('created_at', '>=', now()->subDays(30))
230+ ->get();
231+ ```
232+
223233<!-- #### 💿 Materialized View -->
224234<!-- -->
225235#### 📐 Function
Original file line number Diff line number Diff line change 66
77use CalebDW \SqlEntities \Concerns \DefaultSqlEntityBehaviour ;
88use CalebDW \SqlEntities \Contracts \SqlEntity ;
9+ use Illuminate \Database \Query \Builder ;
10+ use Illuminate \Support \Facades \DB ;
911
1012abstract class View implements SqlEntity
1113{
@@ -53,4 +55,12 @@ public function isRecursive(): bool
5355 {
5456 return $ this ->recursive ;
5557 }
58+
59+ public static function query (?string $ as = null ): Builder
60+ {
61+ $ instance = app (static ::class);
62+
63+ return DB ::connection ($ instance ->connectionName ())
64+ ->table ($ instance ->name (), $ as );
65+ }
5666}
You can’t perform that action at this time.
0 commit comments