Unfortunately, this project has been discontinued

API routes

In this step, we'll write the controller method that will return the list of all posts

Controller setup

Let's start by generating the controller:

php artisan make:controller PostsController

Register in the endpoint in routes/api.php

Route::get('/posts', '[email protected]');

Controller method

<?php

namespace App\Http\Controllers;

use App\Post;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class PostsController extends Controller
{
    public function index()
    {
        $posts = Post::get();

        return response()->success(compact('posts'));
    }
}