Projects

All snippet related to projects

 

Adding a Poll record with validation in restful api

Step 01: Setting up route for store() method in PollController in routes/api.php Route::post( '/polls', [PollController::class,'store']); Step 02: Adding store() method...


Editing a Poll record with validation

Step 01: setting up route for store() method in PollController in routes/api.php Route::put( '/polls/{id}', [PollController::class,'update']); Step 02: adding update() method...


Deleting a Poll record with validation

Step 01: setting up route for delete() method in PollController in routes/api.php Route::delete( '/polls/{id}', [PollController::class,'delete']); Step 02: adding delete() method...


Searching Poll records with query string and using eloquent when

We will be changing index() method like below of PollController for this purpose //In PollController.phppublic function index() { //dd(request('search_title')); $polls...


Using transformers to transform api response data

Sometimes our api response data need to be transferred in certain way to achive our desired need. For example, formatting...


Seeding Question data for a poll

Step 01: running artisan command to create question factory, seeder, migration and model files php artisan make:model Question -mfs Step...


Bulding endpoints for Question resources

Similar to Poll resource we will be implementing endpoints for question resources that is browsing, adding, reading, editing and deleting...


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...


Fetching questions under poll in restful api ( nested data )

Step 01: In PollController changing setup like below from previous setup public function show($id) { $poll = Poll::find($id); if(is_null($poll)){ return...


Pagination for poll in restful api

It is achieved in simple one step process like below by modifying index() method in PollController.php public function index() {...