Download the PHP package zenithsu/laravel-plus without Composer
On this page you can find all versions of the php package zenithsu/laravel-plus. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download zenithsu/laravel-plus
More information about zenithsu/laravel-plus
Files in zenithsu/laravel-plus
Package laravel-plus
Short Description Laravel-Plus is an efficient Laravel extension package designed to enhance development productivity. It integrates powerful annotation handling and practical helper classes, making the development of Laravel applications more convenient and flexible.
License MIT
Informations about the package laravel-plus
Laravel Plus
Laravel is an elegant framework that greatly simplifies development. However, no framework is truly "out-of-the-box" ready for all use cases; customization based on individual habits and project requirements is often necessary.
Laravel Plus addresses this need by incorporating AOP concepts from Java's Spring Boot and extensively utilizing PHP 8 attributes to streamline the development process.
This project is currently under development. Please be cautious when using it in a production environment.
Installation
This is installable via Composer as https://packagist.org/packages/zenithsu/laravel-plus.
Easy Router
In Laravel, routes need to be configured separately in web.php
or api.php
, which is not convenient during development as it requires switching between different files.
In contrast, frameworks like Spring Boot or Flask allow route configuration using annotations, making the coding process more fluid. Therefore, I have encapsulated annotation-based routing.
First, you need to register in api.php, the code is as follows:
Then, you can use route annotations before controller methods:
You can access this API via /api/login
. In addition to GetMapping
, PostMapping
, PutMapping
, and DeleteMapping
are also supported.
Furthermore, you can add a Prefix annotation to the controller to uniformly add a route prefix for all methods within the controller.
Request
In Laravel-Plus, inspired by SpringBoot's RequestBody annotation, you can use a class to carry parameters from the body:
Then, you can use the RequestBody annotation to inject parameters from the body:
Validators
In Laravel, parameter validation is not a difficult task. However, it can be made even simpler through the use of annotations.
First, you need to enable the parameter validation middleware:
Then, you can use the Param annotation to validate parameters:
The rule
supports Laravel's built-in rules, except for regular expressions.
For particularly complex rules, it is recommended to use custom validators:
In the example above, I wrote a custom rule for a common password validation:
By default, all parameters are required. You can use the required
parameter to set them as optional, and use the default
parameter to set default values:
Bean
Long-term dependency, PHPers are accustomed to using powerful arrays as carriers for all data. This is not an elegant practice and has the following problems:
- Array keys are easily misspelled, and when these errors are discovered, it's already at runtime.
- The coding process is not smooth; you always need to pause to think about what the next key is.
- It violates the single responsibility principle, often having all data in one huge array.
- It reduces code extensibility, readability, and robustness...
Therefore, I introduced the concept of Bean. A Bean is a data carrier with strongly typed properties, allowing you to get better hints during the coding process:
You can initialize a Bean using an array, which is the most common method.Of course, sometimes you can also convert from one Bean to another Bean, and it will filter out mismatched fields:
You can easily convert a Bean to an array or JSON, By default, snake case naming will be used. You can turn off this feature using the usingSnakeCase parameter:
Sometimes, you may need to compare two Beans:
Often, we need to perform preliminary work such as type conversion on the data passed from the client:
You can even perform XSS filtering.
A particularly useful feature of Beans is their support for nesting:
It even supports array nesting:
Autowired
In the Java Spring Boot framework, the @Autowired
annotation is used to automatically inject dependencies. In Laravel-Plus, we can use the #[Autowired]
annotation to achieve the same effect。
The #[Autowired]
annotation can be used on properties. The #[Service]
annotation is used to mark the class as a service, which is required for autowiring.