I'm following the information here:
http://laravel.com/docs/eloquent#one-to-many
I have an assets and sizes table.
An asset has many sizes.
So in my asset model I have:
class Asset extends Eloquent {
public function sizes()
{
return $this->hasMany('sizes');
}
}
But when I do:
Asset::find(1)->sizes;
I get:
Class 'sizes' not found
Where am I going wrong?
Migrations are:
Schema::create('assets', function($table){
$table->increments('id');
$table->string('title');
});
Schema::create('sizes', function($table){
$table->increments('id');
$table->integer('asset_id')->unsigned();
$table->foreign('asset_id')->references('id')->on('assets');
$table->string('width');
});
My classes are also namespaced:
In my controller:
<?php namespace BarkCorp\BarkApp\Lib;
use BarkCorp\BarkApp\Asset;
then later:
Asset::find(1)->sizes;
My models:
Asset:
<?php namespace BarkCorp\BarkApp;
use \Illuminate\Database\Eloquent\Model as Eloquent;
class Asset extends Eloquent {
public function sizes()
{
return $this->hasMany('BarkCorp\BarkApp\Size');
}
}
Size:
<?php namespace BarkCorp\BarkApp;
use \Illuminate\Database\Eloquent\Model as Eloquent;
class Size extends Eloquent {
}
sizes
that extendsEloquent
. – Kemal Fadillahcomposer dumpautoload
to ensure it's picked up all your classes. – alexrussell