Запрос
127.0.0.1:8000/api/posts к Laravel 8 возвращает HTML.
PostsController:
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use App\Models\Post;
use Illuminate\Http\Request;
class PostsController extends Controller
{
public function index()
{
return Post::all();
}
}
api
<?php
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Api\PostsController;
Route::middleware('auth:api')->get('/user', function (Request $request) {
return $request->user();
});
Route::resource('posts', PostsController::class);
route:list
Ответ:
Скриншот кода удалён модератором.