```php public function index() { $exams = Exam::where('enable', 1) ->orderBy('created_at', 'desc') ->take(10) ->get(); return view('exam.index', compact('exams')); } ``` ``` 2. `where()`用來指定條件,我們指定有啟用的測驗 3. `orderby()`用來指定排序,我們指定用建立時間做反向排序(由新到舊) 4. `take()`用來抓出數量 5. `get()`取得資料  6. 若要用兩個(and)篩選條件: ```php $exams = Exam::where('enable', 1) ->where('created_at', '>', '2018-05-30') ``` 7. 若要用 or,則用閉包+orWhere()方式: ```php $exams = Exam::where(function ($query) { $query->where('enable', 1) ->orWhere('user_id', 1); }) ``` 8. 詳情可參考: [](https://github.com/tad0616/exam56/commit/7d4b8ff66afb824600db5ec94e57b266bae06ffe)
進階搜尋