Tutorial by Examples

<?php if (!function_exists('document')) { function document($text = '') { return $text; } } Create a helpers.php file, let's assume for now it lives in app/Helpers/document.php. You can put many helpers in one file (this is how Laravel does it) or you can split them up b...
Now let's create a service provider. Let's put it under app/Providers: <?php namespace App\Providers; class HelpersServiceProvider extends ServiceProvider { public function register() { require_once __DIR__ . '/../Helpers/document.php'; } } The above service pr...

Use

Now you can use the function document() everywhere in your code, for example in blade templates. This example only returns the same string it receives as an argument <?php Route::get('document/{text}', function($text) { return document($text); }); Now go to /document/foo in your brows...

Page 1 of 1