Submit Your Project / Idea

We are actively looking for cool ideas of packages / projects to develop. Have an idea, or need a specific package developed that you're having trouble finding elsewhere? Drop a message on the Reddit forum and let us know!

Your idea may get developed free of charge and open sourced, or maybe will be developed and released commercially for a small license fee, or maybe will spawn a great discussion and even better ideas! If your idea is picked up, it will be listed on the Projects page.

Jump in and share your ideas! Don't be left behind, get modern and professional with Apex!

Visit Reddit Forum

Admin Screenshot

Apex Training - Library

Let's create a quick library for our lottery package. Libraries and simply blank PHP files which can coonnain any and all code you wish. Within terminal, type:

./apex create lib training:lottery

This will create a new blank PHP file at /src/training/lottery.php. Open the file, and enter the following contents.

declare(strict_types = 1);

namespace apex\training;

use apex\app;
use apex\svc\db;
use apex\svc\debug;
use apex\transaction\tx;
use apex\transaction\processor;
use apex\app\msg\emailer;

 * Class that handles all lottery functionality.
class lottery

     * @Inject
     * @var emailer
    private $emailer;

 * Picke a winner.
 * @return int The id# of the user who won.
public function pick_winner()

    // Get random user
    if (!$userid = db::get_field("SELECT id FROM users WHERE status = 'active' ORDER BY RAND()")) { 
        return false;

    // Get total users
    $total = db::get_field("SELECT count(*) FROM users");

    // Add to database
    db::insert('lotteries', array(
        'userid' => $userid, 
        'amount' => app::_config('training:daily_award'), 
        'total_entries' => $total) 
    $lottery_id = db::insert_id();

    // Add transaction
    $tx = app::make(tx::class);
    $tx->set_user((int) $userid);
    $tx->set_amount((float) app::_config('training:daily_award'));
    $tx->set_reference_id((int) $lottery_id);

    // Create transaction
    $processor = app::make(processor::class);

    // Process e-mails
    $this->emailer->process_emails('lottery', (int) $userid, array('status' => 'complete'), array('lottery_id' => $lottery_id));

    // Return
    return(int) $userid;



This library simply contains one method that will pick the winner of the lottery, add a transaction to their account, and send out any necessary e-mail notifications. If you will notice, this library also takes advantage of dependency injection via annotations with the e-mailer class.


Let's move on to creating that Crontab Job, which will run every 24 hours and execute out one method in the above library.