This project has been archived. If you're curious, check out one of my latest courses:
If you work with JavaScript, check out the fetch use cases and JavaScript projects.
Thank you! — Jad Joubran
Let's start by generating the controller:
php artisan make:controller PostsController
Register in the endpoint in routes/api.php
Route::get('/posts', 'PostsController@index');
<?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'));
}
}