33 lines
884 B
PHP
33 lines
884 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;
|
|
private $paginationSize = 10;
|
|
|
|
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)
|
|
{
|
|
$recipes = $this->recipesRepository->paginate($this->paginationSize);
|
|
|
|
return response()->json(['success' => true, 'data' => ['recipes' => $recipes]], 200);
|
|
}
|
|
}
|