Download the PHP package teksite/extralaravel without Composer
On this page you can find all versions of the php package teksite/extralaravel. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download teksite/extralaravel
More information about teksite/extralaravel
Files in teksite/extralaravel
Package extralaravel
Short Description this package add some features such as rules, middlewares, functions to laravel
License MIT
Informations about the package extralaravel
ExtraLaravel
A collection of reusable utilities, helpers, casts, validation rules, traits, Artisan commands, route macros and Laravel developer tools.
ExtraLaravel is designed to provide commonly needed functionality for Laravel applications without introducing unnecessary dependencies or forcing a specific architecture.
Features
- Custom Eloquent Casts
- IP Address Cast
- Jalali Date Cast
- Slug Cast
- Custom Validation Rules
- Iranian National Code
- Mobile Number
- Strong Password
- No HTML
- Never Pass
- API Form Request with standardized JSON validation responses
- Phone Verification Trait
- Soft Delete / Trash Management Trait
- Custom Artisan Generator Commands
- Cache Cleanup Command
- Honeypot Middleware
- Recursive Blade Directive
- Useful Global Helpers
- Configurable package behavior
- Route macro for soft-deleted resources
Requirements
- PHP 8.2+
- Laravel 10+
- Laravel 11+
- Laravel 12+
The package is designed to work with modern Laravel applications.
Installation
Step 1: Install via Composer
Install the package through Composer:
Step 2: Register the Service Provider
For Laravel > 9
Add the service provider to the bootstrap/providers.php file:
For Laravel 5.x and Earlier
Add the service provider to the config/app.php file under the providers array:
Note: Laravel 5.5 and above supports auto-discovery, so this step is not required for newer versions.
Configuration
Publish the package configuration:
Or publish a specific configuration group if you expose individual publish tags.
The package configuration can contain:
Eloquent Casts
IP Cast
The IpCast automatically uses the request IP address when no value is explicitly provided.
When creating a model:
The current request IP will be stored automatically.
You can also explicitly provide an IP:
Jalali Date Cast
JalaliDateCast provides automatic Jalali/Gregorian conversion based on the current application locale.
When the application locale is:
the date is converted to Jalali when reading the model.
When saving a Jalali date, it can be converted back to Gregorian automatically.
The cast expects the following helper functions to be available:
If these functions are unavailable, the original value is returned.
Slug Cast
The SlugCast automatically converts a value into a URL-friendly slug.
Example:
The stored value becomes:
Enum Files
The package provides Enum files for various purposes, such as:
- Areas: Geographic regions
- Langs: Language settings
- Currencies: Currency formats
- LocalLangs: Localized language settings
- MobilePatterns: Mobile number formats
Validation Rules
Iranian National Code
Validate an Iranian National Code using:
The rule validates the 10-digit Iranian national identification code and its check digit.
Mobile Number Rule
The MobileRule supports country-specific mobile number validation through the package's MobilePatterns enum.
Example:
By default, Iran is used:
You can also specify a country:
Or multiple countries:
The exact supported countries depend on the available MobilePatterns enum values.
Password Rule
Validate password strength:
The rule checks for:
- Lowercase characters
- Uppercase characters
- Numbers
- Special characters
- Minimum password length
No HTML Rule
Prevent HTML tags from being submitted:
For example:
is accepted, while:
is rejected.
This rule is intended for validation. It should not be considered a replacement for output escaping or XSS protection.
Never Pass Rule
NeverPassRule is a rule that always fails validation.
This can be useful for temporarily disabling fields or testing validation flows.
API Form Request
The package provides:
Instead of Laravel's default validation response, validation errors are returned as JSON.
Example:
A validation failure returns a response similar to:
Authorization failures return:
Phone Verification
The MustVerifyPhone trait provides phone verification functionality similar to Laravel's email verification system.
Add the trait to your User model:
Your model must have:
columns.
Check Phone Verification
Returns:
or:
Mark Phone as Verified
Mark Phone as Unverified
Get Phone for Verification
By default, the value of:
is returned.
Send Verification Notification
The model using this trait must implement:
This allows the package to remain independent of a specific SMS provider.
Trash / Soft Delete Management
The TrashMethods trait provides a reusable API for managing soft-deleted models.
Your model must use Laravel's:
trait.
Example manager:
Count Trashed Records
Get Trashed Records
Custom pagination:
Restore Records
Restore one record:
Restore multiple records:
Restore All
Permanently Delete Records
Permanently delete one:
Multiple records:
Permanently Delete Everything in Trash
wipe()andwipeAll()use Laravel'sforceDelete()and permanently remove records.
Trash Resource Routes
ExtraLaravel provides a trashResource() route macro for creating standardized soft-delete routes.
Example:
This can generate routes for:
| Action | Method | URI |
|---|---|---|
| Index | GET | /users/trash |
| Reinstate | PATCH | /users/trash/{id} |
| Prune | DELETE | /users/trash/{id} |
| Restore | PATCH | /users/trash |
| Flush | DELETE | /users/trash |
The controller should provide the corresponding methods:
Route Middleware
Middleware can be supplied through the options array:
Custom Prefix
Custom Route Name Prefix
Only Specific Actions
Exclude Actions
Artisan Commands
ExtraLaravel provides several custom Artisan commands.
API Request Generator
Create an API Form Request:
Example nested request:
The generated class extends:
Logic Generator
Create a Logic class:
Nested class:
Logic classes can be used for database queries and application-specific business/query logic.
Trash Controller Generator
Create a soft-delete controller:
For an API controller:
Cache Purge Command
ExtraLaravel provides:
The command can clean:
- Expired database cache
- Expired file cache
- Expired Sanctum tokens
Dry Run
To inspect what would be deleted without deleting anything:
Force Production Execution
By default, destructive execution in production asks for confirmation.
To force execution:
Batch Size
Default batch size:
Custom:
Skip Database Cache
Skip File Cache
Skip Sanctum Tokens
Custom Database Connection
Honeypot Middleware
ExtraLaravel provides a simple honeypot middleware to detect automated form submissions.
Configuration:
Register the middleware in your application according to your Laravel version and apply it to the routes/forms you want to protect.
Example form field:
The field should normally remain empty.
If a request submits a non-empty honeypot field, the middleware rejects the request.
Blade Recursive Directive
ExtraLaravel provides a recursive Blade directive.
Example:
It can be used for recursively rendering nested arrays or traversable data.
For arrays stored in variables that may need casting:
Helper Functions
ExtraLaravel provides several global helper functions.
changeToSlug
Convert text to a slug:
Result:
Custom separator:
toEnglishNumber
Convert Persian and Arabic digits to English digits:
Result:
Arabic digits are also supported:
normalizePersianText
Normalize common Arabic characters to their Persian equivalents:
The helper also removes Arabic diacritics.
convertSeconds
Convert seconds to:
Example:
Result:
You can request an array:
Result:
currentUrlWithoutQueries
Get the current URL without query parameters:
exploding
Split a string using both English and Persian commas:
Returns a Laravel Collection.
var_export_short
A shorter array representation of var_export():
To return the generated string:
arrayToDot
Convert Laravel-style array notation to dot notation:
Result:
dotToArray
Convert dot notation to array-style notation:
Result:
normalizePath
Normalize filesystem paths:
is_rtl
Determine whether a language is RTL:
Result:
If no language is provided, the current application locale is used:
get_error
Retrieve validation errors using array-style field names:
getStaticData
Read static data from PHP files using dot notation.
Example directory:
If tehran.php contains:
You can retrieve it using:
Result:
A default value can be provided:
Suggested Project Structure
A typical application using ExtraLaravel can organize its code as:
Generated classes can then follow a predictable structure:
Design Philosophy
ExtraLaravel intentionally focuses on small, reusable Laravel components rather than providing a large framework on top of Laravel.
The package follows several principles:
- Prefer Laravel's native functionality where possible.
- Keep utilities independent from application-specific business logic.
- Avoid unnecessary dependencies.
- Make functionality configurable.
- Provide reusable Artisan generators.
- Keep API responses predictable.
- Keep validation rules independent and composable.
- Support Persian/Jalali-oriented Laravel applications without forcing them on other applications.
Security Notes
ExtraLaravel does not replace Laravel's built-in security mechanisms.
In particular:
- Always use Laravel's authorization system.
- Always escape user-controlled output.
- Do not rely on
NoHtmlRuleas your only XSS protection. - Validate and sanitize uploaded files independently.
- Protect destructive commands in production.
- Restrict trash management routes using proper authentication and authorization.
- Do not expose permanent-delete endpoints without authorization.
- Configure honeypot fields correctly.
Contributing
Contributions are welcome.
Before submitting a pull request:
- Write or update tests.
- Follow Laravel coding conventions.
- Run the test suite.
- Run static analysis if configured.
- Run the code formatter.
- Keep changes focused and backwards compatible where possible.
License
This package is open-sourced software licensed under the MIT license.
See the LICENSE file for more information.
Roadmap
Possible future additions:
- More Laravel-specific validation rules
- Additional Eloquent casts
- More reusable traits
- Additional Artisan generators
- Improved API response helpers
- More storage utilities
- Queue-related utilities
- Additional Persian/Jalali helpers
- Expanded automated test coverage
Author
Developed by Sina Zangiband.
Contact
- Website:
- Email: [email protected]