EDDYMENS

Published a year ago

A Row Must Be An Array Or A TableSeparator Instance | Laravel Artisan Fix

If you try using the Laravel artisan output command $this->table, you might end up with the error A row must be an array or a TableSeparator

This means whatever the method is getting is either not an array or in a format that is usable by the method.

First check to be sure the data being passed is an array. You can use the dd or dump helper for this.

If you can confirm you are passing in an array then the next thing to check is the array format.

01: // Your array should have a format similar to the one below. 02: $bio = [ 03: ['name' => 'Jane Doe', 'age' => 32], 04: ['name' => 'John Doe', 'age' => 35], 05: ]; 06: return $this->table(['name', 'age'], $bio); 07: 08: // Output: 09: +----------+-----+ 10: | name | age | 11: +----------+-----+ 12: | Jane Doe | 32 | 13: | John Doe | 35 | 14: +----------+-----+

Your array should be in a specific format to get it to render as a table.

Each data component within your array should have one of the keys you provide to the table method. The example above shows each data set in the array (line 02 to line 05 above) has either name or age which are the columns set on line 06 as well.

Here is another article you might like 😊 A Way To Avoid Filling In Required Fields