2019-12-15 15:45:22 +01:00
|
|
|
<?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)
|
|
|
|
{
|
2019-12-15 21:09:14 +01:00
|
|
|
$filters = $this->getFilters($request);
|
|
|
|
$recipes = $this->recipesRepository->paginate($filters);
|
2019-12-15 15:45:22 +01:00
|
|
|
|
|
|
|
return response()->json(['success' => true, 'data' => ['recipes' => $recipes]], 200);
|
|
|
|
}
|
|
|
|
}
|