does you variable fillable or hiden in Market are strings?
Jun 30, 2016
4
Level 3
array_flip() error when calling Model::all()
Hey everyone. I'm having an issue with listing records from my "Market" model using
$markets = App\Models\Market::all();
Here is the error I receive when executing this using artisan tinker:
PHP warning: array_flip() expects parameter 1 to be array, string given in /home/vagrant/www/trust dale/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php on line 458
App\Models\Market.php:
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Market extends Model
{
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'markets';
/**
* A featured_id belongs to one business.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsToOne
*/
public function featured()
{
return $this->belongsToOne('App\Models\Business', 'id', 'featured_id');
}
}
Level 6
It looks like you might be overriding $fillable in your model, and you've set it to a string instead of an array. Simply remove that (or change it to an array) and things should work again.
Also, you don't need to set the value for $table as you're naming conforms to the convention. It's only necessary if you don't follow the convention of:
Singular model names: i.e SomeEntity Plural table names: i.e some_entities
Please or to participate in this conversation.