Giter VIP home page Giter VIP logo

laravel-helpers's Introduction

View & Action Helpers

Version License


Laravel helpers package lets you use and create custom view/action helpers.

Installation

Pull package:

composer require unckleg/laravel-helpers

Register service provider in config/app

...
Unckleg\Helpers\HelpersServiceProvider::class,

Example

Create app/Helpers directory or run command:

php artisan make:helper Hello --type=View
  • Hello - Name of View Helper
  • type - View or Action

Command will create directory and Helper for you.

  • Helper
<?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 }
}
  • In blade
@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

Built-in helpers

  • @javascripts()  @includeJs()    @endjavascripts()
  • @stylesheets() @includeCss() @endstylesheets()
  • @routeName()

Notes

If you experience permission error while using commands make sure you grant permissions for Helpers directory.

laravel-helpers's People

Contributors

unckleg avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.