1
我在處理laravel中的路由組時如何將全局範圍添加到路由組中,有點麻煩。我所做的是Laravel路徑組全球範圍
Route::group([
"prefix" => "customer",
"namespace" => "Customer",
"as" => "Customer.",
], function() {
//make sure only public salons are displayed!
\App\Salon::addGlobalScope("public", function(\Illuminate\Database\Eloquent\Builder $builder) {
$builder->where("public", 1);
});
Route::get("/", "[email protected]")->name("index");
Route::get("/salon/{salon}", "[email protected]")->name("salon.show");
});
這個想法是我希望公衆查詢被添加到整個組中!這包括在沙龍模型和路由綁定上調用newQuery。這是可能的嗎?假設我是懶惰的,而不是定義一個路由綁定並將範圍添加到每個用戶,我寧願在這裏做,因爲我需要在整個組中的綁定!
感謝提前:)