Reputation: 12358
I'm performing a simple insert which I've done many times without any issues and for some odd reason it's not working and I get this error message:
error: {type: "ErrorException", message: "Array to string conversion",…}
file: "C:\wamp\www\studentreg2\vendor\laravel\framework\src\Illuminate\Database\Grammar.php"
line: 33
message: "Array to string conversion"
type: "ErrorException"
Here's my code:
$advisorCheck = AdvisorCheck::create([
'status' => Input::get('status'),
'application_id' => Input::get('id'),
'user_id' => Auth::id()
]);
The migration for the advisor_check table which AdvisorCheck model uses seems fine, all foreign keys are unsigned and show the relations correctly in phpmyadmin, all values from the Input::get are strings, the model has the correct fields set as fillable (status, application_id, user_id).
I've even tried doing this in php artisan tinker
like this:
AdvisorCheck::create([ 'status' => 'returned', 'application_id' => '3', 'user_id' => '4']);
and I get this response: Array to string conversion
I've also tried this method and get the same error:
$advisorCheck = new AdvisorCheck;
$advisorCheck->status = Input::get('status');
$advisorCheck->application_id = Input::get('id');
$advisorCheck->user_id = Auth::id();
$advisorCheck->save();
Model code:
<?php
class AdvisorCheck extends \Eloquent {
protected $fillable = ['status', 'application_id', 'user_id'];
protected $table = ['advisor_check'];
}
If you need to see more code please ask.
Many thanks to anyone who can help!
Upvotes: 9
Views: 31572
Reputation: 41
if we give table name in laravel model like array:
protected $table = ['thoughts'];
then it will generate error.
so you should give table name as string like :
protected $table = 'thoughts';
Upvotes: 0
Reputation: 4084
$table
should be a string not array
<?php
class AdvisorCheck extends \Eloquent {
protected $fillable = ['status', 'application_id', 'user_id'];
protected $table = 'advisor_check';
}
Upvotes: 2
Reputation: 152860
As you can see in the example that's shown in the Laravel docs the table property is a string and not an array
protected $table = 'advisor_check';
Which makes total sense if you think about it, since Eloquent models don't support multiple tables natively.
Upvotes: 27