Create simple Restful API with Laravel (Part 2)

Tram Ho

In the previous section, we have learned about migration, this part we will continue with Controller and Routes:

To create a controller type the following command:

$php artisan make:controller ApiController

This way, the ApiController.php file is created in the directory app http controllers:

Add functions as below:

app http controllers ApiController.php

Next, we need to create a Route to lead to the methods via the Controller:

routes / api.php:

Note: note that all APIs have a prefix of / api, e.g. http: // localhost / api / students

In this article, we successfully created the Controller and Route pointing to which Controller and method. In the next article, we will dive in to define each of the functions available in the Controller.

Share the news now

Source : Viblo