<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Recipe;
use App\RecipeIngredient;
use App\User;

class RecipeController extends Controller
{
  public function index()
  {
    //Pass all users
    $recipes = Recipe::with('user')->get();
    return view('recipes.index')->with('recipes', $recipes);
  }
  public function show($id)
  {
    $recipe=Recipe::with('user')->with('ingredients')->findOrFail($id); 
    return view('recipes.show')->with('recipe', $recipe);
  }
  public function edit($id){
    $recipe=Recipe::with('user')->with('ingredients')->findOrFail($id);
    $ingredients=RecipeIngredient::get()->sortby('name')->pluck('name')->unique();
    return $ingredients;
  }
}
