
How to publish API and broadcasting routes in Laravel 11
Starting from Laravel 11, new projects get to experience a slimmer skeleton. Parts of the efforts to make it happen was to remove some of the route files which can be overwhelming for new developers.
That being said, as your application grows, you might need to create a RESTful API or broadcast events into channels for an app leveraging WebSockets.
To publish the API routes file in Laravel 11 and up, use:
php artisan install:api
This command will create the routes/api.php file, but also install Laravel Sanctum, create some migrations, and add a config/sanctum.php file.
And to publish the broadcasting channels routes file, use:
php artisan install:broadcasting
After running the command, Artisan will also ask you if you want to install Laravel Reverb.
Did you like this article? Then, keep learning:
- Add Alpine.js to Laravel for UI enhancements complementary to broadcasting
- Use Laravel to build interactive features like ChatGPT plugins
- Learn to clear Laravel's cache to handle issues post-route publishing
- Learn to customize middleware classes for Laravel 11's new skeleton
- Step-by-step upgrade guide to Laravel 11 for context and benefits
- Explore Laravel 11's key changes and new features in detail
- Best practices for building RESTful APIs with Laravel complement publishing API routes
- Secure your REST API using Laravel Sanctum, installed with API routes
- How to publish config files in Laravel 11's minimalist skeleton
- Master Artisan commands like those to publish routes in Laravel 11