Download the PHP package achyutn/laravel-helpers without Composer
On this page you can find all versions of the php package achyutn/laravel-helpers. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download achyutn/laravel-helpers
More information about achyutn/laravel-helpers
Files in achyutn/laravel-helpers
Informations about the package laravel-helpers
Laravel Helpers
Installation
You can install the package via composer:
Usage
Traits
You can use following traits for your models:
HasTheSlug
This trait is used to generate slug for your model. It uses cviebrock/eloquent-sluggable package.
Note:
You must have slug
column in your table. And the source is by default title
column but can be changed by setting the $sluggableColumn
property in your model.
HasTheMedia
This trait is used to add media conversions over the HasMedia
trait from spatie/laravel-medialibrary package.
or alternatively, you can extend your model using the MediaModel
class provided by the package:
You can use:
cover()
to get original image (in format:WebP
).small_cover()
to get small image (in format:WebP
).medium_cover()
to get medium image (in format:WebP
).large_cover()
to get large image (in format:WebP
).
Multiple Collections
You can also define multiple collections in your model. For example, if you want to have a gallery
and a profile
collection along with the default cover
collection, you can do it like this:
You can then access these collections using the same methods as above:
HasTheDashboardTraits
This trait is used to add HasTheSlug
and HasTheMedia
traits to your model.
CanBeApproved
This trait adds approval logic to your Eloquent models using timestamp-based flags (approved_at
, rejected_at
). By default, only approved records are returned in queries due to a global scope.
Make sure your model's table includes approved_at
and rejected_at
columns:
Then, use the trait in your model:
Methods
Method | Description |
---|---|
setApproved() |
Marks the model as approved (sets approved_at , clears rejected_at ) |
setRejected() |
Marks the model as rejected (sets rejected_at , clears approved_at ) |
setPending() |
Resets approval state (clears both approved_at and rejected_at ) |
Scope
The trait adds a global scope to only include approved records. You can override it using the following query macros:
Macro | Description |
---|---|
withPending() |
Includes approved and pending records |
onlyPending() |
Only records where both approved_at and rejected_at are null |
withoutApproved() |
Records that are not approved (includes pending & rejected) |
withRejected() |
Rejected records (rejected_at not null, approved_at null) |
onlyRejected() |
Strictly rejected records (regardless of previous approval) |
withAll() |
Removes global scope and returns all records |
Custom Column Names
You can override the default column names by defining constants in your model:
CanBeInactive
This trait allows Eloquent models to be marked as inactive or active, using a nullable inactive_at
timestamp column. By default, only active models are returned from queries due to a global scope.
Setup
Ensure your model's table includes an inactive_at
column:
Then, use the trait in your model:
Methods
Method | Description |
---|---|
setInactive() |
Marks the model as inactive (sets inactive_at to current time) |
setActive() |
Marks the model as active (clears the inactive_at column) |
Scopes
This trait applies a global scope to include only active models by default. Use the following macros to override:
Macro | Description |
---|---|
withInactive() |
Includes both active and inactive models |
withoutInactive() |
Excludes inactive models (same as default scope) |
onlyInactive() |
Returns only inactive models |
Custom Column Name
You can override the column name by defining a constant in your model:
Nepali Helpers
You can simply use following helper functions:
english_nepali_number
Converts english number to nepali number.
english_nepali
To select value based on the locale.
Validations
LatitudeRule
This rule ensures that the given value is a numeric latitude within the valid range -90
to 90
.
LongitudeRule
This rule ensures that the given value is a numeric longitude within the valid range -180
to 180
.
All versions of laravel-helpers with dependencies
spatie/laravel-medialibrary Version >=8.0
cviebrock/eloquent-sluggable Version >=11.0