Skip to content
Advertisement

How to separate commas into separate row from laravel form add?


I am getting Argument 1 passed to IlluminateDatabaseGrammar::parameterize() must be of the type array, string given this error when i use explode() to add in mysql database


Here is my code

$tags = new Tag;

$commas = "test,hello,hi";
$separate_tags = explode(',', $commas);
$tags->tag_name = $separate_tags;

$tags->save();

Advertisement

Answer

Here issue is you are trying to insert an array as string. To save this you have too do this as given below:

$commas = "test,hello,hi";
$separate_tags = explode(',', $commas);

foreach($separate_tags as $separate_tag){
  $tags = new Tag;
  $tags->tag_name = $separate_tag;
  $tags->save();
}
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement