Jump to content

Listener not working


Skytraveler

Recommended Posts

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 by Skytraveler
Link to comment
Share on other sites

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

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...