Does the ProcessRecurringTransactions command class have a constructor that makes a query using the Code model class? All command constructors are executed whenever the app is running in the console (i.e. running any artisan command).
Issue with laravel system. (php artisan)
Hello, I'm not sure what I have done, but I seem to now have an issue with my laravel system -- Any time I issue ANY artisan command(seed, clear) or even composer dump autoload.. , I get the following error (below). I'm not sure why is trying to execute this code, can someone point me in the right direction please?
php artisan cache:clear
ErrorException
Trying to get property 'code_value' of non-object
at C:\laragon\www\code\app\Code.php:33
29| {
30|
31| return Code::where('major_code',$majorCode)
32| ->where('minor_code',$minorCode)
> 33| ->first()->code_value;
34|
35| }
36|
37| public static function getCodeDescription($majorCode, $minorCode, $codeValue)
1 C:\laragon\www\code\app\Code.php:33 Illuminate\Foundation\Bootstrap\HandleExceptions::handleError
("Trying to get property 'code_value'
of non-object", "C:\laragon\www\code\app\Code.php", ["GENERAL", "TIMEZONE"])
2 C:\laragon\www\code\app\Console\Commands\ProcessRecurringTransactions.php:52
App\Code::getCodeValue("GENERAL", "TIMEZONE")
Not exactly; Laravel needs to instantiate every console command in order to match the signature (which is a protected property on the Class). In doing so, the constructor is invoked (obviously). So, because you have a query inside the constructor of one of the commands, that query is being executed.
Consider either (i) moving the query into the handle method, or (ii) coding defensively, i.e. do not assume you will get a Code instance and return a default :
return Code::where('major_code',$majorCode)
->where('minor_code',$minorCode)
->first()->code_value ?? null;
Please or to participate in this conversation.