Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/omnicode/lara-tools
Useful tools for Laravel
https://github.com/omnicode/lara-tools
laravel utility
Last synced: 2 days ago
JSON representation
Useful tools for Laravel
- Host: GitHub
- URL: https://github.com/omnicode/lara-tools
- Owner: omnicode
- License: mit
- Created: 2017-07-02T07:43:11.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2020-08-21T22:10:34.000Z (about 4 years ago)
- Last Synced: 2024-10-21T03:02:37.608Z (24 days ago)
- Topics: laravel, utility
- Language: PHP
- Homepage:
- Size: 19.5 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Lara Tools - Convenient tools for Laravel
## Contents
1. LaraUtil
* hasTable
* hasColumn
* getFullColumns
* hashPassword
* verifyPassword
2. ModelExtrasTrait
* saveAssociatedLaraUtil contains the following utility methods
Checks if the given table exists - caching the result, returns true or false
```
LaraUtil::hasTable('users')
```Checks if the given table has the given column - caching the query, returns true or false
```
LaraUtil::hasColumn('users', 'first_name')
```Accepts the columns list and the table name and adds the table name into columns if does not exist e.g.
```
$columns = ['id', 'first_name', 'users.last_name'];
$columns = LaraUtil::getFullColumns($columns, 'users');// the final array will look like
['users.id', 'users.first_name', 'users.last_name']
```Hashes the given string by bcrypt, however afterwards encrypting the password's hash by application-side key. It also applies `sha256` method (before hashing) to remove bcrypt's length restriction - [more](https://security.stackexchange.com/a/6627/38200)
```
$hashedAndEcryptedPassword = LaraUtil::hashPassword('some password');
```
will be string like this
`eyJpdiI6IlU4amxZaVNCc2xjemlkZUNWRFVhb3c9PSIsInZhbHVlIjoidWs0bmRcL1JFMHk1dUE4Yk9kWFo3b2VSZEJuYXk5NngwUXMxMDBieTdvOVZ6d1JWQ3RObVE3RGZmcHlqYnV1Ymw5OFVKelRlb2JsSllcL21FVlk4WklVNHkzcnl5Ym90T0tJVzNZalRyUmI2dz0iLCJtYWMiOiI2MDE3ZTQ1NGE0NDcwNTY2Yjc3NzAyZmZlOWU4ZDBkMTE4ODNhNTY0YTE2ZmYzNDNkNDA0ZGI2ZWRhZjhjMTA3In0=`Verifies the password hashed by `hashPassword` method above - returns true or false
```
$passwordMatch = verifyPassword('plan text password', $hashedAndEcryptedPassword);
```ModelExtrasTrait is a trait to be used in Models - provides the following methods
`saveAssociated` method is a wrapper method, that allows to save `BelongsToMany` and `HasMany` related models in a single transaction, e.g. suppose we need to save a product with its related categories, we would use
```
Product::saveAssociated($data, ['associated' => 'categories']);
```the `$data` should be an array like this
```
$data = ['name', 'price', 'categories_ids' => [1, 3, 7]]
```