ClearBowl/api/app/Http/Controllers/RecipesController.php

33 lines
885 B
PHP

<?php
namespace App\Http\Controllers;
use App\Http\Requests\AddRecipeRequest;
use App\Repositories\RecipesRepositoryInterface;
use Illuminate\Http\Request;
class RecipesController extends Controller
{
private $recipesRepository;
public function __construct(RecipesRepositoryInterface $recipesRepository)
{
$this->recipesRepository = $recipesRepository;
}
public function add(AddRecipeRequest $request)
{
$recipe = $this->recipesRepository->create(collect($request->all()));
return response()->json(['success' => true, 'data' => ['recipe' => $recipe]], 200);
}
public function index(Request $request)
{
$filters = $this->getFilters($request);
$recipes = $this->recipesRepository->paginate($filters);
return response()->json(['success' => true, 'data' => ['recipes' => $recipes]], 200);
}
}