Support the ongoing development of Laravel.io →
posted 10 years ago
Architecture

Hello!

I use some external API, like twilio and others. I wonder what is the best practices where should I put the logic. For example, usually I'm able to find some package which does the work for me, but sometimes I need to write it by myself. What I do: I create an app/service folder where I put some classes, like, Twilio.php. In the constructor I initialize tokens/authentication. An example is: http://laravel.io/bin/NkbvG#12

I wonder if it's okay or should I consider refactoring? I haven't ever created any packages and I want to use the API only in this project, so that's what I have so far.

Another much more important thing is where to put this logic: I need to send notifications for users. In order to do that I use cron, since I need to check DB state every minute. So, in Laravel 5 we have scheduler. When I've tried to use repositories directly in scheduler they didn't get injected. Anyway, I wouldn't put all my notifications in the single scheduler method, so I've taken an example from documentation and made an artisan command. But I'm not sure if it's a right place to make many artisan commands for each cron command, how do you think?

Thanks in advance!

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Victor victor Joined 18 Nov 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.