Closed newtonianb closed 11 years ago
There is no src/models/console.php
file. What are you using?
Oh sorry that was from a fork, I re-downloaded the latest from your branch here is the updated error, very similar
{"error":{"type":"ErrorException","message":"PDO::quote() expects parameter 1 to be string, object given","file":"/home/dd/project/vendor/darsain/laravel-console/src/Darsain/Console/Console.php","line":142}}
Can you paste the seeding that causes this error? Or the minimum code needed to replicate the issue.
Thanks for helping debug this. After your input I debugged a little more within that seed file and found the line causing the issue
This is what causes the error specified above but this error only occurs on seeding when console is enabled in app.php otherwise it works fine when console is commented out ...
$fullform->sequencing()->attach(Attr::where('slug', 'dnb')->first()->id, array('value' => '30KLR'));
sequencing() is
public function sequencing() {
return $this->belongsToMany('Attr')->withTimestamps()->withPivot('value');
}
Can you give me migrations and models for Attr and whatever $fullform
is? Or in other words, all files necessary to replicate this.
http://paste.laravel.com please
Sorry for the delay. Here is a full example of the issue https://github.com/newtonianb/console_error/tree/master/app/database/migrations
php artisan migrate --seed
or php artisan migrate:refresh --seed
This works fine without darsain console however when you enable 'Darsain\Console\ConsoleServiceProvider'
in config/app.php
then the error starts coming up on seeding.
{"error":{"type":"ErrorException","message":"PDO::quote() expects parameter 1 to be string, object given","file":"vendor\\darsain\\laravel-console\\src\\Darsain\\Console\\Console.php","line":142}}
Thx. I was able to replicate it. Gonna fix it now.
Thank You. I'm curious though why was this an issue, is the console intercepting everything no matter if its ran from the console interface or not? Does that affect performance in production?
Well, first of all - as it is advised with a bold text in the index of this repo - this package should get nowhere near your production server. It is strictly for development environment.
And yes, the console query listener is being registered in ConsoleServiceProvider::boot
method, i.e. in loading process, before anything starts actually executing. That is also before we know what route did we hit, so it is registered for all of them. That is the only way how to log all queries. If I'd attach query listener in console controller, I might miss tons of queries like user authentication, options loaded from DB, ... etc.
The issue was that listener doesn't receive the query in it's full string form, but before the bindings have been applied. Usually bindings are strings, so all you need to do is:
$sql = preg_replace('/\?/', $binding, $sql, 1);
But in your case, there was a DateTime
object being passed as $binding
, so it needed to be stringified.
I get this error when running php artisan migrate:refresh --seed