Package Data | |
---|---|
Maintainer Username: | unckleg |
Maintainer Contact: | djordjestojilljkovic@gmail.com (Djordje Stojiljkovic) |
Package Create Date: | 2017-05-29 |
Package Last Update: | 2017-06-12 |
Home Page: | |
Language: | PHP |
License: | MIT |
Last Refreshed: | 2024-11-22 03:15:21 |
Package Statistics | |
---|---|
Total Downloads: | 218 |
Monthly Downloads: | 0 |
Daily Downloads: | 0 |
Total Stars: | 0 |
Total Watchers: | 1 |
Total Forks: | 0 |
Total Open Issues: | 0 |
Laravel helpers package lets you use and create custom view/action helpers.
Pull package:
composer require unckleg/laravel-helpers
Register service provider in config/app
...
Unckleg\Helpers\HelpersServiceProvider::class,
Create app/Helpers directory or run command:
php artisan make:helper Hello --type=View
Command will create directory and Helper for you.
<?php
namespace App\Helpers;
class Test
{
/**
*
* Blade calling: @test::helloWorld()
*
* @return string
*/
public function helloWorld()
{
return 'Hello world';
}
/**
*
* Blade calling: @test::helloTo(array $people)
*
* @param array $people
* @return string
*/
public function helloTo(array $people)
{
return implode(', ', $people);
}
/**
*
* Blade calling: @test::navigation()
*
* @return string
*/
public static function navigation()
{
$pages = App\Page::all();
?>
<div class="navigation">
<ul>
@foreach($pages as $page)
<li>
<a href="{{ Url::slugify(app()->baseUrl($page->title)) }}">
{{ $page->title }}
</a>
</li>
@endforeach
</ul>
</div>
<?php }
}
@test:helloWorld()
// outputs: Hello world
@test::helloTo(['One', 'Two', 'Three', 'Four', 'Five'])
// outputs: One, Two, Three, Four, Five
@test::navigation()
// outputs: This will output whole html provided in navigation method
If you experience permission error while using commands make sure you grant permissions for Helpers directory.