I am working on laravel and following the tutorial http://technetlk.blogspot.com.au/2012/09/laravel-backbonejs-coffeescript_3527.html. currently working on 7th part of this tutorial.
in routes.php I have written
Route::any('api/category/(:num?)',
array('as' => 'api.category',
'uses' => 'api.category@index')
);
In api/category.php,
<?php
class Api_Category_Controller extends Base_Controller
{
public $restful = true;
public function get_index($id = null)
{
if (is_null($id ))
{
$allCats = Category::all();
return BaseModel::allToJson($allCats);
}
else
{
$cat = Category::find($id);
return $cat->toJson();
}
}
public function post_index()
{
$cat = Input::json();
$dbCat = new Category();
$dbCat->code = $cat->code;
$dbCat->name = $cat->name;
$dbCat->save();
return $dbCat->toJson();
}
public function put_index()
{
$cat = Input::json();
$dbCat = Category::find($cat->id);
$dbCat->code = $cat->code;
$dbCat->name = $cat->name;
$dbCat->save();
return $dbCat->toJson();
}
public function delete_index($id = null)
{
$dbCat = Category::find($id);
$dbCat->delete();
}
}
?>
and in BaseModel.php
<?php
class Category extends BaseModel
{
public static $table = 'tbl_category';
}
class BaseModel extends Eloquent
{
public function toJson()
{
return json_encode($this->to_array());
}
public static function allToJson($array)
{
$temp = array();
foreach($array as $t)
{
$temp[] = $t->to_array();
}
return json_encode($temp);
}
}
?>
when I am trying to run
curl -X POST http://lbc.dev/api/category -H "Content-Type: application/json" –d '{"code":"cat1", "name":"Category One"}'
I am getting the follwing error
Unhandled Exception
Message:
Class 'Category' not found Location:
C:\xampp\htdocs\NewBlog\application\controllers\api\category.php on line 9