Download the PHP package mookofe/laravel-support without Composer
On this page you can find all versions of the php package mookofe/laravel-support. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download mookofe/laravel-support
More information about mookofe/laravel-support
Files in mookofe/laravel-support
Package laravel-support
Short Description Awesome enhancements for your current Laravel Models, Collections and more.
License MIT
Informations about the package laravel-support
mookofe/laravel-support
Awesome enhancements for your current Laravel Models, Collections.
Features
- Simple setup
- Awesome new features for your current Models
- New features for your Collections
Requirements
- illuminate/support: 5.*
Version
1.0.1
Installation
Preparation
Open your composer.json file and add the following to the require array:
Install dependencies
Or
Integration
Change inheritance on your models, instead of using the default Eloquent Model change as follow:
Using Model features:
Getting human dates from model fields
This method works both for string and carbon dates fields.
Check if an attribute exists in the model
This function verify if an attribute already exists in the current model.
Get changes in a model
Return an array with the affected properties.
Create new model from existing using only specific fields
Create a new instance only with the fields specified
Remove model fields
Allows you to remove fields in model
Using Collection features:
Our model is configured to use our collection which extends from Eloquent Collection, so all methods from the Eloquent Collection can be used.
Rebuild collection
Allows you to rebuild a collection using the fields you want. Imagine you have a user table with the following fields: (id, name, lastname, sex)
Compare collections
Allows you to compare if all values of a field is present in another collection.
Create new instance
Allows you to create a new empty instance of the same type of the current collection
Get latests rows grouped by fields
Return a new collection with the latest rows grouped by the fields specified, in the order of the collection items. Imagine you have a post table with the following fields (id, user_id, post_category_id).
This example allows you to get the latest posts categories for the user.
Get first rows grouped by fields
Return a new collection with the first rows grouped by the fields specified, in the order of the collection items. Using the previous table structure, in this example you get the first posts categories for the user.
Sum values by field in collection
Sum all values matching the search criteria. In this example the function will sum all products prices from category 10.
Find items on collection
Allows you to find items on the collection filter by data in the array. In this example we will filter all products with product category 10 and price 100.
Merge collections
Merge fields from the new collection if values matches. In this example we will merge the avatar file path to the user model.
Custom value for found item
Allows you to return a custom value if the item you are looking for it's been found. If no option is specified the model is returned.
Delete all models from collection
Allows you to delete all models from the database in the current collection.
Collection average by field
Allows you to get the average by a field
Find items not matching the filter
Allows you to find items on the collection not matching the filter criteria. In this example we will filter all products where product category is different to 10.
Get maximum item by field name
Get the max value of the given key and return the item. In this example the function will return the max user from the collection.
Convert collection to flat array
Convert the entire collection to a single array using the value of the property specified in the parameter.
License
This package is open-sourced software licensed under the MIT license