EDIT: Added my model's namespace section.
I have a working custom Artisan command but once I start inserting a model which I created I'm immediately greeted with an error.
<?php namespace App\Command;
use App\Models\Samplemodel;
public function fire()
{
$name = $this->argument('name');
// This next line won't work
$age = Samplemodel::get_age($this->option('bday')); // Line 42
$this->line("My name is {$name} and my age is {$age}.");
}
I'm always met with the error:
{"error":{"type":"Symfony\\Component\\Debug\\Exception\\FatalErrorException","message":"Class 'App\\Models\\Samplemodel' not found","fi
le":"X:\\xampp\\htdocs\\laralabs\\laralabs.app\\app\\commands\\SampleCommand.php","line":42}}{"error":{"type":"Symfony\\Component\\De
bug\\Exception\\FatalErrorException","message":"Class 'App\\Models\\Samplemodel' not found","file":"X:\\xampp\\htdocs\\laralabs\\larala
bs.app\\app\\commands\\SampleCommand.php","line":42}}
I removed the other methods from this sample code to keep things clean. That's basically it, does that mean I can't use a model when creating a custom Artisan command?
As requested, the first few lines of my model:
<?php namespace App\Models;
use DB;
use Config;
use Eloquent;
use DateTime;
class Helper extends Eloquent { ... }
The actual name of my model is Helper. This class doesn't have any properties only methods.
php artisan command:make SampleCommandlike in the docs. The error comes up only when I insert the use ofSamplemodel. If there are no models it works fine.App\Models? How about not writing theuseline, does it help? Show your model file contents please.App\Models. @Antonio, the actual model is pretty long (and is in use so it works just fine) which is why I made a sample which is what you see now. Let me run more tests...