Support the ongoing development of Laravel.io →
Requests Database

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?

Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.