A collection of utility classes and traits to streamline common Laravel development tasks, including error handling, paginated responses, data handling, middleware creation, a base repository for advanced filtering, keyset pagination, base query filtering, and more. This package aims to reduce boilerplate code often encountered in Laravel projects.
jerrydepredator/laravel-predator-api-utils is a Laravel package for a collection of utility classes and traits to streamline common laravel development tasks, including error handling, paginated responses, data handling, middleware creation, a base repository for advanced filtering, keyset pagination, base query filtering, and more. this package aims to reduce boilerplate code often encountered in laravel projects..
It currently has 0 GitHub stars and 97 downloads on Packagist (latest version v0.0.9).
Install it with composer require jerrydepredator/laravel-predator-api-utils.
Discover more Laravel packages by jerrydepredator
or browse all Laravel packages to compare alternatives.
Last updated
This package provides a collection of utility classes and traits to streamline common Laravel development tasks, such as:
This package aims to reduce boilerplate code often encountered in "MY LARAVEL PROJECTS" by providing reusable components. It was created based on my personal preferences and may not be suitable for all projects or development styles. It is not intended to be a comprehensive solution for all Laravel development needs and may require customization for specific requirements.
Install via Composer:
composer require jerrydepredator/laravel-predator-api-utils
Publish Configuration (Optional):
If you want to customize the default property names for the DecryptedJWToken service, publish the configuration file:
php artisan vendor:publish --provider="LaravelPredatorApiUtils\ServiceProvider" --tag="config"
This will create a config/decrypted_jwt_token.php file in your project where you can modify the property names.
Location: src/Services/DecryptedJWToken.php
Purpose: Provides methods to access data from a decrypted JWT token.
Usage:
use LaravelPredatorApiUtils\Services\DecryptedJWToken;
// In your controller
public function showProfile(Request $request, DecryptedJWToken $decryptedJWToken)
{
$userId = $decryptedJWToken->getUserId();
$userName = $decryptedJWToken->getUserName();
$userData = $decryptedJWToken->getData(); // Get all user data
// ... your logic using user data
}
DecryptJWToken:
src/Middlewares/DecryptJWToken.phpAuthorization header and adds the decrypted data to the request object.Register the middleware in app/Http/Kernel.php:
protected $routeMiddleware = [
// ... other middleware
'decrypt_jwt' => \App\Http\Middleware\DecryptJWToken::class,
];
Apply the middleware to routes:
Route::get('/protected-route', [MyController::class, 'showData'])->middleware('decrypt_jwt');
RoleMiddleware:
src/Middlewares/RoleMiddleware.phpRegister the middleware in app/Http/Kernel.php:
protected $routeMiddleware = [
// ... other middleware
'role' => \App\Http\Middleware\RoleMiddleware::class,
];
Apply the middleware to routes:
Route::get('/admin', [AdminController::class, 'index'])->middleware('role:admin');
ApiResponse:
src/Traits/ApiResponse.phpHandlesErrors:
src/Traits/HandlesErrors.phpPaginationRules:
src/Traits/PaginationRules.phpsrc/Repositories/BaseRepository.phpdecrypted_jwt_token.php:
config directory.DecryptedJWToken service.Contributions are welcome! Please submit pull requests to the project's GitHub repository.
This package is licensed under the MIT License.