0
public function scopePublished($query) {
$query->where('published_at', '<=', Carbon::now());
}
$查詢參數是如何通過這裏的?該函數是否將參數$ query傳遞給它自己?
下面是函數調用:
public function index() {
$articles = Article::latest('published_at')->published()->get();
return view('articles.index', compact('articles'));
}
這不是一個編程問題。查看[Laravel的源代碼](https://github.com/laravel/framework/tree/5.2/src/Illuminate/Database/Eloquent),如果你有興趣瞭解它如何工作。 –