Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

iristechph's avatar

Exception: Array to string exception

I'm having a problem with this method.

$table->foreign(['created_by', 'updated_by'])->references('id')->on(['users', 'users'])->onDelete('cascade');

on old Laravel version the syntax above works, but when I do it in current version of Laravel it throw an exception

ErrorException  : Array to string conversion

  at C:\Users\japet\Desktop\mh\vendor\laravel\framework\src\Illuminate\Database\Grammar.php:39
    35|      */
    36|     public function wrapTable($table)
    37|     {
    38|         if (! $this->isExpression($table)) {
  > 39|             return $this->wrap($this->tablePrefix.$table, true);
    40|         }
    41|
    42|         return $this->getValue($table);
    43|     }

  Exception trace:

  1   Illuminate\Foundation\Bootstrap\HandleExceptions::handleError("Array to string conversion", "C:\Users\japet\Desktop\mh\vendor\
laravel\framework\src\Illuminate\Database\Grammar.php", [])
      C:\Users\japet\Desktop\mh\vendor\laravel\framework\src\Illuminate\Database\Grammar.php:39

  2   Illuminate\Database\Grammar::wrapTable()
      C:\Users\japet\Desktop\mh\vendor\laravel\framework\src\Illuminate\Database\Schema\Grammars\Grammar.php:216

Is this deprecated or just have other syntax to use

0 likes
6 replies
bobbybouwmann's avatar

You have the wrong syntax here. It should be this

$table->foreign('created_by')->references('id')->on('users')->onDelete('cascade');
$table->foreign('updated_by')->references('id')->on('users')->onDelete('cascade');
iristechph's avatar

I use that syntax to reduce the repetition of $table->foreign but in the newer version of Laravel the method is deprecated I think.

$table->foreign(['created_by', 'updated_by'])->references('id')->on(['users', 'users'])->onDelete('cascade');

This method is working on Laravel 5.8 but not on 6.x

Snapey's avatar

out of interest, how does a timestamp field relate to users.id primary key ?

l don't see what you are trying to achieve

iristechph's avatar

its not a time stamp created_by not created_at its a user interaction with the data

Snapey's avatar

ah, blurry morning eyes to blame...

Please or to participate in this conversation.