0

I have this error : ErrorException in helpers.php line 748: preg_replace(): Parameter mismatch, pattern is a string while replacement is an array

SerialController.php

public function createSerial(Request $request)
    {
        $serial = new Serial();
        $serial->nume_serial = $request['numeSerial'];
        $serial->claritate = $request['claritate'];
        $serial->aparitie = $request['aparitie'];
        $serial->genuri = $request['genuri'];

        $serial->save();
        return redirect('/admin');
    }

view

<div class="checkbox">
                SF<input type="checkbox" name="genuri[1]" value="sf" id="">
            Biografic<input type="checkbox" name="genuri[2]" value="biografic" id="">
            Animat<input type="checkbox" name="genuri[3]" value="animat" id="">

        </div>
5
  • Strange. My helpers.php does not have any preg_replace inside. Did you change something in the framework? Commented May 15, 2016 at 15:47
  • @codedge, helpers.php has this line at 748 $subject = preg_replace('/'.$search.'/', $value, $subject, 1); Commented May 15, 2016 at 15:57
  • @AlexeyMezenin Which Laravel version? I am using the latest 5.2.x . You mean /vendor/laravel/framework/src/Illuminate/Foundation/helpers.php? Really strange, cannot see any preg_replace Commented May 15, 2016 at 16:01
  • 1
    @codedge, /vendor/laravel/framework/src/Illuminate/Support/helpers.php Commented May 15, 2016 at 16:03
  • 1
    @AlexeyMezenin Thanks a lot! Wrong file ;) Commented May 15, 2016 at 16:05

2 Answers 2

1

I guess a problem is you're trying to insert an array into a DB table.

$serial->genuri = $request['genuri']; // it's an array

You could convert an array to a json data:

$serial->genuri = json_encode($request['genuri']);

Of course you have to change genuri data type to JSON:

$table->json('genuri');
Sign up to request clarification or add additional context in comments.

5 Comments

FatalErrorException in SerialController.php line 19: Call to a member function toJson() on array
migrate error : [PDOException] SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error i n your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'json not null) default character set utf8 collate utf8_unicode_ci' at line 1
So, you're trying to change genuri data type to json with new migration? Please share new migration code.
public function up() { Schema::create('seriale', function (Blueprint $tableSeriale) { $tableSeriale->text('nume_serial'); $tableSeriale->text('claritate'); $tableSeriale->integer('aparitie'); $tableSeriale->json('genuri'); }); }
It seems you're trying to create new table over existing one. If you want to use this way, you should rollback first. But I guess safer way is to create new migration and change one field only.
0

Apparently from looking at your view, $request['genuri'] is an array, and the error is this line $serial->genuri = $request['genuri']; since you are assigning an array to an object property that is string (I think?) in your DB table.

Not sure what you are trying to accomplish, if you provide more info I might help more.

1 Comment

i want to insert two values in database in the same column

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.