Package Data | |
---|---|
Maintainer Username: | CurtisSaunders |
Maintainer Contact: | cgsaunders97@gmail.com (Curtis Saunders) |
Package Create Date: | 2017-01-13 |
Package Last Update: | 2019-12-04 |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-22 03:12:43 |
Package Statistics | |
---|---|
Total Downloads: | 724 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 6 |
Total Watchers: | 3 |
Total Forks: | 1 |
Total Open Issues: | 0 |
This package requires PHP 5.6+, and includes a Laravel 5 Service Provider.
To install through composer include the package in your composer.json
.
"curtissaunders/laravel-helpers": "^1.0"
Run composer install
or composer update
to download the dependencies or you can run composer require curtissaunders/laravel-helpers
.
To use the package with Laravel 5, add the Helper Service Provider to the list of service providers
in app/config/app.php
.
'providers' => [
CurtisSaunders\LaravelHelpers\HelpersServiceProvider::class
];
{{ versioned_asset('images/photo.png') }}
outputs:
http://mysite.com/images/photo.png?v=392104829
{{ concat('John', 'Terry', 'Dave') }}
outputs:
John Terry Dave
{{ concat_ws(' - ', 'John', 'Terry', 'Dave') }}
outputs:
John - Terry - Dave
{{ generate_uuid() }}
outputs:
e4eaaaf2-d142-11e1-b3e4-080027620cdd
When using the generate_uuid
function, you are able to generate valid RFC 1, 3, 4 and 5 versions. In order to change
the version, simply pass the version number you require as the first argument (defaults to 1). For example, to generate
a version 4 Uuid, you can do the following:
{{ generate_uuid(4) }}
outputs:
25769c6c-d34d-4bfe-ba98-e0ee856f3e7a
For versions 3 and 5, you are also required to pass in a string as the second argument. This is hashed and used when generating the Uuid. For example:
{{ generate_uuid(3, 'php.net') }}
outputs:
11a38b9a-b3da-360f-9353-a5a725514269
Examples shown in Laravel Blade
@if(route_is('about.index'))
// Do something
@else
// Do something else
@endif
Alternatively
@if(routeIs('about.index'))
// Do something
@else
// Do something else
@endif
You can also check for specific parameters by passing them in an array as the second argument. For example, you may want to check that you're on a specific product category to apply an "active" class to a link. Consider the below when looping through category links:
@foreach($categories as $category)
<a href="{{ route('product.category', [$category->slug]) }}" class="{{ route_is('product.category', ['categorySlug' => $category->slug]) ? 'active' : '' }}">
{{ $category->name }}
</a>
@endforeach
The above would apply a class of "active" when you're on the corresponding page to that link.
// Enable laravel's query log
DB::connection()->enableQueryLog();
... // Do database transactions ...
// Get all the queries ran since the query log was enabled
$queryLog = DB::getQueryLog();
// Combine the query logs ran with their bindings into the sql that was ran
$sqlQueries = query_log_to_sql($queryLog);
// Returns an array of all the sql queries ran with their bindings in place, useful for quick debugging
dd($sqlQueries);
// Create a query using Eloquent
$eloquentQuery = UserModel::where('email', '=', 'user.name@example.com');
// Combine the Eloquent query sql and bindings into a query you can run in mysql
$sqlQuery = combine_query($eloquentQuery->toSql(), $eloquentQuery->getBindings());