Service classes are written to encapsulate codes and business logic separately from controllers. These classes should work for a service or operation. Unlike other classes, service classes do not inherit from other classes or controllers. Instead, the functions get called by object.
Convention:App\Http\Services
namespace.PostService
, CommentService
etc.If you are working with laravel and still writing code like a junior developer without using some useful features for some structural methods is not that much good for big projects and your future opportunities.
I'd like to write about some useful techniques you can implement in your project development with laravel. It might be API or any web application.
The techniques are:
You can write one line of code for defining a route for a CRUD operation, instead of writing different routes. This is called Resource Routes.
Why we need this?
Resource routes are a way of defining a set of routes that map to the various CRUD (Create, Read, Update, and Delete) operations for a resourceful controller.
1. Optimizes time and code.
2. Structured way.
3. Universal standard.
Laravel WebSockets is a package for Laravel 5.7 and up that will get your application started with WebSockets in no-time! It has a drop-in Pusher API replacement, has a debug dashboard, realtime statistics and even allows you to create custom WebSocket controllers.
The package will automatically register a service provider.
This package comes with a migration to store statistic information while running your WebSocket server.
Read more