Commit 79d849de authored by King Alex's avatar King Alex

Model Search pour faciliter et unifier les recherches

parent c2b760c8
<?php
class Search extends Eloquent {
protected $recipes;
function __construct($search){
// TODO create repository
if(is_null($search)){
return null;
}
$searchIngredients = Ingredient::where('name', 'LIKE', '%'.$search.'%')->get();
$searchCategory = Category::where('display_name', 'LIKE', '%'.$search.'%')->first();
$searchRecipes = Recipe::where('title', 'LIKE', '%'.$search.'%')->orwhere('description', 'LIKE', '%'.$search.'%')->get();
// find all recipes that share an id with the search ingredients
if(is_null($searchIngredients)){
}else{
foreach($searchIngredients as $ingredient){
$this->recipes[] = $ingredient->recipes()->first() ;
}
}
if(is_null($searchRecipes)){
}else{
foreach($searchRecipes as $recipe){
$this->recipes[]=$recipe;
}
}
if(is_null($searchCategory)){
}else{
$recipeList=$searchCategory->recipes()->get();
foreach ($recipeList as $recipe) {
$this->recipes[] = $recipe;
}
}
}
function get(){
return $this->recipes;
// TODO remove duplicates
}
}
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