Skytraveler Posted May 22, 2023 Report Share Posted May 22, 2023 (edited) Hi, I'm tryng to create a new expense listener for hard landing events, by adding a new file at /app/Listeners, but it's not working. I have this Laravel error: Quote production.ERROR: Class "App\Listeners\Expense" not found {"userId":1,"exception":"[object] (Error(code: 0): Class \"App\\Listeners\\Expense\" not found at /home/flyeircm/crew.flyeag.com/app/Listeners/ExpenseTouchdown.php:27) This is the code I'm using: <?php namespace App\Listeners; use App\Contracts\Listener; use App\Events\Expenses; class ExpenseTouchdown extends Listener { public function handle(Expenses $event) { $expenses = []; $amount = 250; // Do your check here, return an empty array if it is ok/below your check limit (no expense needed) if (abs($event->pirep->landing_rate) < 500) { return $expenses; } // You can even increase the punishment here by getting a ratio // So the harder they land, the higher the punishment $amount = round($amount * (abs($event->pirep->landing_rate) / 500)); // Prepare a New Expense here $expenses[] = new Expense([ 'type' => ExpenseType::FLIGHT, // This must be FLIGHT for a pirep related pilot charged expense 'amount' => $amount, // No need to add two more digitis, 150 is 150$ or 150Eur etc. 'transaction_group' => 'Hard Landing', // This is the group name, visible at financial report 'name' => 'Hard Landing Fee For Pirep='.$event->pirep->id, // Name is visible like a memo 'multiplier' => false, // or true (to use Subfleet GH Multiplier) 'charge_to_user' => true, // true to charge pilot, false to charge company ]); // If you wish you can create another expense here like the one above... // And finally return all new expenses you prepared return $expenses; } } I believe the code is right, I adapted from an example at the forum. I cleaned the cache. The filename and the inner class name declaration are matching. Anyone can help me to find where the problem might be? Thanks. Edited May 22, 2023 by Skytraveler Quote Link to comment Share on other sites More sharing options...
DisposableHero Posted May 23, 2023 Report Share Posted May 23, 2023 <?php namespace App\Listeners; use App\Contracts\Listener; use App\Events\Expenses; use App\Listeners\Expense; //This is missing // Rest looks ok That missing line is the reason for Class "App\Listeners\Expense" not found error. Hope it works Quote Link to comment Share on other sites More sharing options...
DisposableHero Posted May 23, 2023 Report Share Posted May 23, 2023 I checked my own custom expenses (provided by my module), it is slightly different from the example <?php namespace Modules\DisposableSpecial\Listeners; use App\Events\Expenses; use App\Models\Enums\ExpenseType; use App\Models\Expense; // You can try this too If "App\Listeners\Expense" fails, try "App\Models\Expense" and see what happens. Good luck Quote Link to comment Share on other sites More sharing options...
Skytraveler Posted May 24, 2023 Author Report Share Posted May 24, 2023 Thanks, it worked by adding use App\Models\Expense; and also the following that was on your code above: use App\Models\Enums\ExpenseType; Thank you very much for your help once again, Quote Link to comment Share on other sites More sharing options...
DisposableHero Posted May 24, 2023 Report Share Posted May 24, 2023 Great news, glad somehow my examples helped Enjoy your new expenses Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.