Reputation: 18756
I'm trying to use Faker library inside my home controller, but I don't know how to include it. The library's documentation uses this:
require_once '/path/to/Faker/src/autoload.php';
$faker = Faker\Factory::create();
But Laravel has a different way of loading classes, but I didn't find an example with such a library.
So how do I do that?
Upvotes: 0
Views: 4544
Reputation: 1719
I guess you added it using composer? I use a lib that I have installer with composer (Imagine) and I wanted to use composer loading script so I did this in start.php:
// Composer package
require_once $GLOBALS['laravel_paths']['base'] . 'vendor' . DS . 'autoload.php';
Upvotes: 1
Reputation: 2405
You should look at Registering a namespace, it should take care of what you need. Faker follows the PSR0 standard for namespaces, so you need need to tell laravel how to find those files. In your application/start.php
file place these directives:
Autoloader::namespaces(array(
'Faker' => path('libraries').'path/to/Faker/src/Faker',
));
Hope that helps!
Edit:
Furthermore I realized that if you move the src/Faker folder into application/libraries
as application/libraries/Faker
it should be loaded automatically.
Upvotes: 0