Commit 54f76298 authored by King Alex's avatar King Alex

Ajout API

parent cd0bc170
......@@ -2,36 +2,21 @@
class RecipeController extends BaseController {
// TODO Pass list of top 30 recipes from recent to oldest.
public function list(){
# return list of recipes
public function getList(){
// EAGER Loading
$recipes = Recipe::with(['ingredients', 'images', 'categories', 'users' ])->get();
// TODO Pass list of top 30 recipes from recent to oldest.
$recipes = Recipe::with(['ingredients', 'images', 'categories', 'users' ])->get()->toArray();
$list = [];
foreach($recipes as $recipe){
$recipe_display = new RecipeDisplay($recipe->id);
array_push($list, $recipe_display->get());
}
return View::make('templates.recipe.list')->with('recipes',$list);
}
// Returns
public function get($id){
$recipe_display = new RecipeDisplay($id); // TODO check the id here if it exists.
if(is_null($recipe_display)){
alert('Error: Recipe not found');
return $this->list();
$recipe_display = new RecipeDisplay($recipe["id"]);
array_push($list, $recipe_display->toArray());
}
return View::make('templates.recipe.show')->with('recipe',$recipe_display);
return $list;
}
// Recupereration de la liste categories avec Eloquent
public function create(){
$catList = Category::all();
return View::make('templates.recipe.create')->with('categories',$catList);
}
public function search(){
# Return Search query results as list
public function getSearch(){
$searchText = Input::get('q');
$search = new Search($searchText);
......@@ -45,10 +30,43 @@ class RecipeController extends BaseController {
$recipe_display = new RecipeDisplay($recipe->id);
array_push($list, $recipe_display->get());
}
return $list;
}
return View::make('templates.recipe.list')->with('recipes',$list);
public function getShow($id){
$recipeDisplay = new RecipeDisplay($id); // TODO check the id here if it exists.
if(is_null($recipeDisplay)){
alert('Error: Recipe not found');
return $this->list();
}
return $recipeDisplay;
}
/**
* VIEWS
*/
public function list(){
return View::make('templates.recipe.list')->with('recipes',$this->getList());
}
public function search(){
return View::make('templates.recipe.list')->with('recipes',$this->getSearch());
}
public function get($id){
return View::make('templates.recipe.show')->with('recipe',$this->getShow($id));
}
// Recupereration de la liste categories avec Eloquent
public function create(){
$catList = Category::all();
return View::make('templates.recipe.create')->with('categories',$catList);
}
// Route::post('recipe/create', 'RecipeController@doCreate');
public function doCreate(){
$recipeData = Input::all();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment