Commit 40b9ea6e authored by King Alex's avatar King Alex

Ajout model pour adapter les donnees a la vue

parent 0e579988
<?php
class RecipeDisplay extends Eloquent {
protected $id;
protected $title;
protected $introduction;
protected $description;
protected $image_path;
protected $category;
protected $ingredients;
protected $owner;
protected $owner_id;
function __construct($id){
$recipe = Recipe::find($id);
if(is_null($recipe)){
return null;
}
// Identifier
$this->id = $id;
// Title
$this->title = $recipe['title'];
// Introduction
$this->introduction = $recipe['introduction'];
// Description
$this->description = $recipe['description'];
// Image thumbnail path
$recipe_image_id = $recipe['images']->first()->id;
$recipe_image_name = (Image::find($recipe_image_id))->name;
$this->image_path = asset('custom/img/uploads/'.$recipe_image_name);
// category
$this->category = $recipe->categories()->first()->display_name;
// ingredients
$ingredient_list = [];
foreach($recipe->ingredients()->get() as $ingredient){
array_push($ingredient_list, $ingredient->name);
}
$this->ingredients = $ingredient_list;
// owner
$this->owner = $recipe->users()->first()->username;
$this->owner_id = $recipe->users()->first()->id;
}
function get(){
return $this;
}
}
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