Created
September 8, 2015 04:18
-
-
Save tofuninjah/8e9affaf88e7320ab847 to your computer and use it in GitHub Desktop.
custom class in Laravel 5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** 3 seconds: | |
* - Library example class | |
* - Updated composer.json | |
* - Example usage in a controller | |
*/ | |
/** | |
* '/library/Hello.php' | |
*/ | |
<?php namespace Library; | |
class Hello { | |
static function world() { | |
return "Hello World!"; | |
} | |
} | |
/** | |
* composer.json (just the autoload part, for brevity) | |
* Note "Library" has been added under "App" | |
* -> Run 'composer dump-autoload' in command line | |
*/ | |
"autoload": { | |
"classmap": [ | |
"database" | |
], | |
"psr-4": { | |
"App\\": "app/", | |
"Library\\": "app/library/" | |
} | |
}, | |
/** | |
* '/app/Http/Controllers/TestController.php' | |
* Note that you'd need to route to this function... | |
*/ | |
<?php namespace App\Http\Controllers; | |
use Library\Hello; | |
class TestController extends Controller { | |
public function index() | |
{ | |
return Hello::world(); // should return "Hello World!" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment