0

the problem is that tinker is not wrapping the content in a string

Illuminate/Database/QueryException with message 'SQLSTATE[HY000]: General error: 1364 Field 'address_line_2' doesn't have a default value (SQL: insert into Test (name, gender, mobile_phone, alternate_phone, status, address_line_1, updated_at, created_at) values (emitchell, dariana66@hotmail.com, Kendra Friesen, Ole Carter, Gennaro Hickle, Prof. Brandon Herman PhD, 2018-12-21 01:07:12, 2018-12-21 01:07:12))'

if I add the quotes manually to every value like

values ('emitchell', 'dariana66@hotmail.com', 'Kendra
Friesen', 'Ole Carter', 'Gennaro Hickle', 'Prof. Brandon Herman PhD',
'2018-12-21 01:07:12', '2018-12-21 01:07:12')

It works

how can I make the random content generate by tinker being in quotes?

I even use (string)

$factory->define(App\Test::class, function (Faker $faker) {
    return [
       'name' => (string)$faker->sentence(),
       'gender' => (string)$faker->sentence(),
       'mobile_phone' => (string)$faker->sentence(),
       'alternate_phone' => (string)$faker->sentence(),
       'status' => (string)$faker->sentence(),
       'address_line_1' => (string)$faker->sentence(),
       'address_line_2' => (string)$faker->sentence(),
       'town_city' => (string)$faker->sentence(),
       'postscode' => (string)$faker->sentence(),
       'notes' => (string)$faker->sentence()
    ];

});

or examples from the github page

'name' => $faker-> sentence($nbWords = 6, $variableNbWords = true), // 'Sit vitae voluptas sint non voluptates.'

it wont output string values...

what is going on ?

Marcogomesr
  • 2,614
  • 3
  • 30
  • 41
  • I haven't used faker or tinker. If `$faker->sentence()` is null then `(string)$faker->sentence()` will be null. Perhaps you can make `address_line_2` nullable? – Adam Rodriguez Dec 21 '18 at 02:27
  • `$faker->sentence()` is not null... it's just no quoting it... I'm getting someting like this `lorem ipsum` without quotes it wont work on mysql... I added manually semicolumns to the sentences `'lorem ipsum'`and it works...thats why I added (string) – Marcogomesr Dec 21 '18 at 12:11

1 Answers1

0

You don't need to specify the data type, you just need to call the function

'name' => $faker->sentence(),

irishman
  • 272
  • 1
  • 2
  • 7