I've defined a model for Eloquent like this:
<?php
class Order extends Eloquent {
public $timestamps = false;
protected $fillable = ['station_id', 'created', 'due', 'month', 'comments', 'name', 'ud', 'dp', 'swrv', 'sh', 'jmsw', 'sw', 'prrv', 'mhsw', 'bmsw', 'mp', 'pr', 'st', 'total_points'];
}
?>
So there are 19 columns listed in the fillable array. When I call Order::find($id)
and return that from a restler method the encoded JSON object has all my fillable columns with their proper values AND 20 extras where the key is the index, so station_id is listed under a 1 key, created is listed under a 2 key, etc...
How do I make it not return those numbered values and just use the $fillable values?
You got it wrong!
fillable
property is for whitelisting what can be filled up by supplying an array of data
for avoiding few fields from being returned in the output, you can use hidden
property instead to provide a blacklist.
Starting from Laravel 4.2.8 you can specify an white list with visible
property as shown below.
class Order extends Eloquent {
public $timestamps = false;
protected $fillable = ['station_id', 'created', 'due', 'month', 'comments', 'name', 'ud', 'dp', 'swrv', 'sh', 'jmsw', 'sw', 'prrv', 'mhsw', 'bmsw', 'mp', 'pr', 'st', 'total_points'];
protected $visible = ['station_id', 'created', 'due', 'month', 'comments', 'name', 'ud', 'dp', 'swrv', 'sh', 'jmsw', 'sw', 'prrv', 'mhsw', 'bmsw', 'mp', 'pr', 'st', 'total_points'];
}