Browsing Poll Questions in restful api

Step 01: Setting up routes in routes/api.php

Route::get( '/polls/{poll}/questions', [PollController::class, 'questions'] );

Step 02: Back in PollController.php adding questions() method

public function questions(Poll $poll) {
	return response()->json($poll->questions,200);
} 


Now endpoint url will be like below    

Browsing all question records
http://localhost:8000/api/polls/3/questions
HTTP Verb: GET

Url above will return all poll questions as json response in postman or user browser

Related Posts


Building RESTful APIs in Laravel

Seeding Poll data

Seeding Question data for a poll

Pagination for poll in restful api

Uploading image in restful api