Open sidebar
namespace App\Http\Controllers; use App\Repositories\ActionRepositoryInterface; use Illuminate\Database\Eloquent\ModelNotFoundException; use Illuminate\Http\Request; use Illuminate\Routing\Controller; abstract class ApiController extends Controller implements ActionRepositoryInterface { protected $model; protected $response; public function index() { $collection = $this->model->all(); return $this->response->respondCollection($collection); } public function store() { } public function show($id) { try { $item = $this->model->findOrFail($id); return $this->response->respondSuccess($item); } catch (ModelNotFoundException $e) { return $this->response->respondNotFound(); } } public function update(Request $request, $id) { try { $item = $this->model->findOrFail($id); $item->fill($request->input())->save(); return $this->response->respondSuccess($item); } catch (ModelNotFoundException $e) { return $this->response->respondNotFound(); } } public function destroy($id) { $this->model->destroy($id); } public function getRequest(){ } }
Close sidebar
Back
Please note that all pasted data is publicly available.
X (fomerly Twitter)
GitHub
Use setting
Back
Please note that all pasted data is publicly available.
X (fomerly Twitter)
GitHub
Use setting