Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make custom libraries in Laravel - as in codeigniter

i'm used to write a lot in codeigniter, where i try to place all logic code inside libraries instead of controllers.

The idea is a controller calls a library that calls a model to get data. So whatever is happening inside a library, can be called from multiple controllers easily, without rewriting code.

Now i'm baby stepping to laravel and i cannot find anything about custom libraries. I perfectly managed to call a model from a controller, but I want to have a controller calling a library and the library calling the model.

I'm not able to find libraries (not packages), do they exist in laravel ?

Thank you.

like image 276
Simos Fasouliotis Avatar asked Aug 07 '17 17:08

Simos Fasouliotis


1 Answers

Laravel works with Services and Providers, you create your service and write a provider for it. Laravel Providers

Also you can have Services Directory which is served through Providers Directory.

like image 174
anwerj Avatar answered Oct 13 '22 12:10

anwerj