2

I am stuck in an error for many days, I want to insert data in database in urdu or arabic language , the problem I am facing is strange the insert query changes the position of variables which throws data truncated error , I have used the same work in register Quer which works fine , I have set character set etc every thing perfect but the problem is during inserting values. I am sending the error query which larave throws.

#
Illuminate\Database\QueryException
SQLSTATE[01000]: Warning: 1265 Data truncated for column 'calor_bane' at row 1 (SQL: insert into `service_attributes` (`calor_bane`, `user_id`, `service_id`) values (کالر, 1, 1))
This is the query elequent  
enter code here
ServiceAttribute::create([
'calor_bane' =>$data['name'], 
'user_id' => 1,
'service_id' => 1
]);
#

The same field is inserted in using User Model, it insert the urdu or arabic text correctly both char set are same but problem occurs in the insert query which moves the places you can see the above query.I have tried query builder and other types but didn't work.

insert into `users` (`name`, `email`, `password`, `updated_at`, `created_at`) values (کالر, mutahir12@gmail.pk, $2y$10$Y5fOtbpy..mgExbTotb1sO6irLlhNePKCfMvHv1JSmgtpOhUC2XLO, 2020-05-19 18:13:16, 2020-05-19 18:13:16)
User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
mutahir
  • 97
  • 3
  • 11
  • Show your create table statement for service_attributes, please. – aynber May 19 '20 at 18:30
  • I think you need to change the database table charset option to some acceptable characters like urdu etc... – Akhtar Munir May 19 '20 at 18:59
  • 1
    Database Chartset = utf8 Database Collation = utf8_general_ci try this if it works – Akhtar Munir May 19 '20 at 19:06
  • I have tried many chart set actually database accept urdu character when directly inserting data into it but the problem is in LARAVEL insert query for that model. The user model does not throw error , the other one throws error. below is the character set. ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci; – mutahir May 20 '20 at 04:22
  • Hi, I have change the data type of field it was "ENUM" type when I converted it to "VARCHAR" String datatype now it is not throwing that error and the the value is inserting successfully. thanks for your suggestions and help. – mutahir May 20 '20 at 05:27

1 Answers1

0

Actually by changing the ENUM data type solved my problem. Thanks all.

mutahir
  • 97
  • 3
  • 11