×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Marcelo Aleks
Added: Apr 21, 2015 10:58 PM
Modified: Apr 21, 2015 10:59 PM
Views: 14
Tags: php laravel
O Service provider deverá ser registrado em config/app.php
  1. <?php namespace App\Providers;
  2.  
  3. use Illuminate\Support\ServiceProvider;
  4.  
  5. class AleksMacroServiceProvider extends ServiceProvider {
  6.  
  7.     /**
  8.      * Bootstrap the application services.
  9.      *
  10.      * @return void
  11.      */
  12.     public function boot()
  13.     {
  14.         require base_path() . '/resources/macros/macros.php';
  15. //        require base_path() . '/resources/macros/macro2.php';
  16.         // etc...
  17.     }
  18.  
  19.     /**
  20.      * Register any application services.
  21.      *
  22.      * @return void
  23.      */
  24.     public function register()
  25.     {
  26.         //
  27.     }
  28.  
  29. }
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37. <?php
  38. //Fonte: http://blog.elenakolevska.com/restful-deleting-in-laravel/
  39. Form::macro('delete',function($url, $button_label='Delete',$form_parameters = array(),$button_options=array()){
  40.  
  41.     if(empty($form_parameters)){
  42.         $form_parameters = array(
  43.             'method'=>'DELETE',
  44.             'class' =>'delete-form',
  45.             'url'   =>$url
  46.             );
  47.     }else{
  48.         $form_parameters['url'] = $url;
  49.         $form_parameters['method'] = 'DELETE';
  50.     };
  51.  
  52.     return Form::open($form_parameters)
  53.             . Form::submit($button_label, $button_options)
  54.             . Form::close();
  55. });
  56.  
  57. //Fonte: http://laravelsnippets.com/snippets/an-icon-link
  58. Form::macro('iconLink', function($url, $title = null, $attributes = array(), $icon = null, $secure = null) {
  59.   $url = url($url,NULL,$secure);
  60.   if (is_null($title) or $title === false) $title = $url;
  61.   return '<a href="'.$url.'"'.HTML::attributes($attributes).'><i class="'. $icon .'"></i> '. HTML::entities($title).'</a>';
  62. });