CodeCanyon
CodeCanyon
Code
Code
Code
Code
Code
Code

Laravel Shortcode for Developers

Laravel Shortcode for Developers

There is nothing too much to say about this. This is a script for laravel developers that let the developer make functions as shortcode and use them in either controller of view. Static of database based dynamic codes can be developed inside the shortcode. There is no special coding skill you need. Just use normal laravel coding style according to the documentation and 2 sample shortcodes and you are ready to go.

In a single word- Easy to use and it is Master to make your project easy

  • Copy App/Helpers/helpers.php to App/Helpers folder of your project.
  • add the following line to “autoload” in composer.json file.
    “files”: [“app/Helper/helpers.php”],
    something like this:
    “autoload”: {
    “classmap”: [
    “database”
    ],
    “files”: [“app/Helper/helpers.php”],
    “psr-4”: {
    “App\\”: “app/”,
    },
    },
  • Run composer dump-autoload in your cmd terminal.
  • If you already have that helpers.php file just copy the codes of App/Helpers/helpers.php to you helpers.php file.
  • Copy Shortcode folder from App/Http/Controllers to your project App/Http/Controllers folder.
  • SampleController.php has a sample shortcode system that you can check how to use.
  • To make the shortcode work in view, use this function:
    {!! generate_shortcode($content) !!}
  • Sample data is given in sample.blade.php in Resources/views folder.
  • How to create a new shortcode:
  • Shortcode without content (single ended shortcode)
    $this->add_shortcode(‘sample1’, function($atts, $content = null){
    extract($this->shortcode_atts(array(
    ‘name’ =>’world’
    ),
    $atts));
    return ‘Hello ’ . $name .’!’;
    });
  • Shortcode with content inside (double ended shortcode):
  • $this->add_shortcode(‘sample2’, function($atts, $content = null){
    extract($this->shortcode_atts(array(
    ‘col’ =>’col-md-12’
    ),
    $atts));
    return ‘ ’.$this->do_shortcode($content).’ ’;
    });
  • here sample1 and sample 2 are name of 2 shortcodes that will be used in content. properties like name in sample 1 and col in sample 2 are optinal but useful for customizations.
  • Where to create shortcodes:
    App/Http/Controllers/Shortcode/Shortcodes.php
    in this file all shortcodes will go under function __construct(){}
by
by
by
by
by
by