php - Laravel returns a html page with data instead of a response json in my script.js
one text
I have to porting a php website in laravel and in my original website JavaScript file i call a fetch in a .php file of contents and return a json. In laravel call the fetch in a {{route('contents')}} and then in web.php i create the route
Route::get("/contents","ContentsController@contents")->name('contents')
. And so in ContentsController.php i create:
function contents(){
$CONTENUTI=[
["title"=>"abc",
"img"=>"https....",
"Id"=>"01"],
["title"=>"def",
.....
];
return response()->json($CONTENTS)
But in my website console there's this message:route('contents') 404 not found i try also with return $CONTENTS but it shows me a white page with the json and not in my view
Source