I've created a custom artisan-command in order to call a controller-function via commandline (without curl). Since there seems to be no way in Laravel 4 to directly call the function I'm dispatching a request like this:
public function fire()
{
$request = Request::create('insert', 'GET', array());
Route::dispatch($request)->getContent();
}
When I call the command via command-line it starts showing the HTML-content the controller-function would output:
php artisan myApp:customCommand
<h1>Insert into Database</h1>
<pre>
but then returns this error:
[PDOException] SQLSTATE[HY000] [1049] Unknown database 'appdatabase'
What can I do about it?
I know it's not technically solving your problem, but you should really not be dispatching requests from artisan commands, and I don't think it'll work, or if it does it'll have some difficult-to-debug side effects.
You need to abstract your controller code into a service and then just call the service from both your command and controller instead of trying to use an artisan command to send HTTP requests to your own application.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community