I have a site running Laravel 4.2 that I am working on right now, the problem is that I have a single model for orders and another child model for items that belong to the order. The items also have a child model for size information and image information.
I have my query:
$orders = Auth::user()->orders()->with('items','items.size','items.image')->get()->toArray();
This returns what I am expecting, but I want to have the results paginated using Laravel's pagination. I had expected this to work:
$orders = Auth::user()->orders()->with('items','items.size','items.image')->paginate( 10 );
This returns a blank white page and a 500 error
and for the life of me I can't figure out how to get this to work correctly.
Here are my various models: User.php
use Illuminate\Auth\UserTrait;
use Illuminate\Auth\UserInterface;
use Illuminate\Auth\Reminders\RemindableTrait;
use Illuminate\Auth\Reminders\RemindableInterface;
class User extends Eloquent implements UserInterface, RemindableInterface {
use UserTrait, RemindableTrait;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'users';
/**
* The attributes excluded from the model's JSON form.
*
* @var array
*/
protected $hidden = array('password', 'remember_token');
protected $fillable = array( 'first_name', 'last_name', 'address', 'city', 'state', 'zip', 'lat', 'lng', 'email', 'phone', 'password', 'hash', 'type', 'blocked', 'created_at', 'updated_at', 'deleted_at' );
public function setPasswordAttribute( $value ) {
return $this -> attributes['password'] = Hash::make( $value );
}
public function projects() {
return $this -> belongsToMany('Project');
}
public function orders() {
return $this->hasMany('PrintOrder');
}
public function bookings() {
return $this -> belongsToMany('Booking');
}
}
PrintOrder.php
use Illuminate\Database\Eloquent\SoftDeletingTrait;
class PrintOrder extends Eloquent {
use SoftDeletingTrait;
protected $dates = ['deleted_at'];
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'print_orders';
protected $fillable = array( 'project_id', 'user_id', 'status', 'created_at', 'updated_at', 'deleted_at' );
public function items() {
return $this->hasMany('PrintOrderItem');
}
}
PrintOrderItem.php
use Illuminate\Database\Eloquent\SoftDeletingTrait;
class PrintOrderItem extends Eloquent {
use SoftDeletingTrait;
protected $dates = ['deleted_at'];
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'print_order_items';
protected $fillable = array( 'print_order_id', 'upload_id', 'size_id', 'quantity', 'created_at', 'updated_at', 'deleted_at' );
public function image() {
return $this->hasOne('Upload','id');
}
public function size() {
return $this->hasOne('PrintSize', 'id');
}
}
Upload.php
use Illuminate\Database\Eloquent\SoftDeletingTrait;
class Upload extends Eloquent {
use SoftDeletingTrait;
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'uploads';
protected $fillable = array( 'user_id', 'project_id', 'thumbnail', 'small','medium','large','original','title', 'description','keywords', 'file_type','file_size','file_extension','created_at', 'updated_at', 'deleted_at' );
protected $dates = ['deleted_at'];
public function categories() {
return $this->belongsToMany('UploadCategory', 'upload_image_categorys');
}
}
PrintSize.php
use Illuminate\Database\Eloquent\SoftDeletingTrait;
class PrintSize extends Eloquent {
use SoftDeletingTrait;
protected $dates = ['deleted_at'];
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'print_sizes';
protected $fillable = array( 'title', 'description', 'cost_actual', 'cost_client', 'status', 'created_at', 'updated_at', 'deleted_at' );
}