Monday, March 14, 2022

[FIXED] How to make custom libraries in Laravel - as in codeigniter

Issue

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.


Solution

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.



Answered By - anwerj

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.