Laravel正确编写中间件组

我不确定我是否正确编写了代码,所以我想请人帮忙

我是这样写的,但是我不确定它是否可以正常工作,我不知道它是否会导致错误

Web.php

Route::get('/', function () {
    return view('welcome');
});

Auth::routes();

Route::get('/home', 'HomeController@index')->name('home');

Route::middleware(['auth'])->group(function () {

    Route::resource('categories','CategoriesController');

    Route::resource('posts','PostsController')->middleware(['auth','verifyCategoriesCount']);

    Route::get('trashed-posts', 'PostsController@trashed')->name('trashed-posts.index');

    Route::put('restore-post/{post}','PostsController@restore')->name('restore-posts');

});

verifyCategoriesCount

   public function handle($request, Closure $next)
    {
        if(Category::all()->count() === 0){
            session()->flash('error','You need to add categories to be able to create a post');

            return redirect(route('categories.create'));
        }

        return $next($request);
    }

我想知道我是否正确编写了这些中间件组

如果我写得不好,请告诉我我做错了什么