use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class Customer extends Model
{
use SoftDeletes;
protected $dates = ['deleted_at'];
protected $fillable = [
'parent_id',
'type_id',
'group_id',
'name',
'tax_no',
'trade_register',
'fund_date',
'note',
'image',
'status',
'created_by',
'updated_by',
'deleted_by'
];
public function contacts()
{
return $this->morphMany('App\Contact','contactable');
}
public function addresses(){
return $this->morphMany('App\Address','addressable');
}
}
public function up()
{
Schema::create('customers', function (Blueprint $table) {
$table->increments('id');
$table->integer('parent_id');
$table->integer('type_id');
$table->integer('group_id');
$table->string('name');
$table->string('tax_no');
$table->string('trade_register');
$table->string('fund_date');
$table->string('note');
$table->string('image');
$table->string('status');
$table->integer('created_by');
$table->integer('updated_by');
$table->integer('deleted_by');
$table->timestamps();
$table->softDeletes();
});
}
$factory->define(App\Customer::class, function (Faker\Generator $faker) {
return [
'parent_id' => 0,
'type_id' => 0 ,
'group_id' => 1 ,
'name' => $faker->company ,
'tax_no' => random_int(10,10),
'trade_register' => random_int(8,8),
'fund_date' => $faker->date() ,
'note' => $faker->paragraphs(3) ,
'image' => $faker->imageUrl(),
'status' => 1 ,
'created_by' => 1 ,
'updated_by' => 1 ,
'deleted_by' => 1 ,
];
});
$ php artisan tinker
>>> factory(App\Customer::class,3)->create();
Illuminate\Database\QueryException with message 'PHP error: Array to string conversion in C:\xampp\htdocs\application\vendor\laravel\framework\src\Illuminate\Database\Connection.php
on line 410 (SQL: insert into `customers` (`parent_id`, `type_id`, `group_id`, `name`, `tax_no`, `trade_register`, `fund_date`, `note`, `image`, `status`, `created_by`, `updated_by`, `deleted
_by`, `updated_at`, `created_at`) values (0, 0, 1, Cole-Macejkovic, 10, 8, 2012-02-03, Aperiam dicta aut et quidem nobis laborum. Sint quod voluptas ad dolor sed culpa beatae. Rerum vero aut
est saepe dolor et. Laudantium dolore ut minus dignissimos consequuntur., http://lorempixel.com/640/480/180771, 1, 1, 1, 2016-08-25 15:12:04, 2016-08-25 15:12:04, ?))'
Are you certain the version is exactly 5.3.2? Line 410 cannot be causing this exception: https://github.com/laravel/framework/blob/v5.3.2/src/Illuminate/Database/Connection.php#L410.
Hmmm. Ping @taylorotwell. Looks like this binding still doesn't work.
Can you create a sample demo Laravel application in a repository that recreates this issue?
That value in your factory is what causes the issue @AhmedFathieg
'note' => $faker->paragraphs(3) ,
$faker->paragraphs(3) return an array, you need to do $faker->paragraphs(3, true) to convert it to a string.
But notice, the column type is varchar I think you need to use text instead in order to be able to store large text.
@taylorotwell ok sir.
@AhmedFathieg have you seen my comment?
@themsaid Thanks Mohammed It's solved
Most helpful comment
That value in your factory is what causes the issue @AhmedFathieg
$faker->paragraphs(3)return an array, you need to do$faker->paragraphs(3, true)to convert it to a string.But notice, the column type is
varcharI think you need to usetextinstead in order to be able to store large text.