Question

I'm a developer who is just migrating from CodeIgniter to Laravel. In CI I had library folder where I could put non database functions, for example email verification etc. In Laravel I couldn't find something like that ? Where can I put such libraries in Laravel 4?

Was it helpful?

Solution

If it is single PHP file containing different functions then you can create a Model class in your Model folder. But this Class will not extend Eloquent. It is a simple class. For example I have a class as General.php containing static methods of general functionality. As Model is autoloaded so I don't need to worry about including file. It is automatically included.

But if it is a directory containing different PHP files or PHP classes then you can create a directory in your app directory and add the path of that directory in providers array in app.php in config directory. You can also create an aliases of your library by putting entry in aliases under providers in app.php.

OTHER TIPS

Create a library (just a folder), namespace it, and set it in config as a provider.

Then you can call it like

new \Foo\Class()
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top