What could be causing Laravel to fail to show the blade template?

I've been learning about Laravel's websocket and following a tutorial on it. I tried to implement the code exactly as shown in the tutorial, but I'm running into some issues. Here is the code for the controller:

class CommentController extends Controller{
public function getcomments(Post $post){
    return response()->json($post->comments()->with('user')->latest()->get());

}
public function addcomment(Request $req, Post $post){
   $comment = $post->comment()->create([
       'body' => $req->body,
       'user_id' => auth::id()
   ]);
   $comment = Comment::where('id', $comment->id)->with('user')->first();
    return $comment->toJson;
}}

And here are the routes defined in the routes/api file:

Route::get('/post/{post}', 'CommentController@getcomments');
Route::middleware('auth:api')->group(function () {
      Route::post('/post/{post}', 'CommentController@addcomment');});

In the tutorial, when the instructor goes to /post/1, it displays the HTML code in the post.blade.php template.

However, when I try the same, this is what I see: enter image description here

Could anyone provide some assistance with this issue? Thanks! :)

Answer №1

It appears that the tutorial video instructed you to access /post/1, but instead you accessed /api/post/1. The API is likely designed to retrieve all comments for a post with id:1, which can be found at /post/1.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The Tailwind preset is generating CSS code, but the webpage is not displaying the intended styles

Can anyone explain why the preset is generating CSS in the output file, but the styles are not displaying in the browser? When I manually write CSS in newstyle.css, it gets outputted to output.css and renders correctly in the browser. I attempted adding t ...

Using Angular 7 to trigger a file download from the server with proper Authorization

I'm facing some challenges while trying to implement a specific functionality with Angular 7 and I could use some assistance. Here's the scenario: We have a service that returns static files (PDFs), but it requires authorization to access the AP ...

Retrieving results from PostgreSQL database using pagination technique

When I'm pagination querying my data from a PostgreSQL database, each request involves fetching the data in this manner: let lastNArticles: Article[] = await Article.findAll({ limit: +req.body.count * +req.body.page, or ...

Swift operations on nested JSON arrays can be tricky to handle efficiently

I am currently working on converting JSON data received from a GET request into a usable array format. The JSON data I am receiving has the following structure: { "elementlist":{ "Ready Position":{ "Neutral Grip":["1,2,3,4,5"], "Back Straight (Conc ...

What is the best way to reject input that includes white space characters?

Need help with validating user names! I currently have an input field for the username: <input type="text" name="username" id="username" class="form-control"value="{{username}}"> I have implemented validation that checks for special characters usi ...

The Angular service encounters issues when interacting with REST API

Within my application, a template is utilized: <div class="skills-filter-input" ng-class="{'hidden-xs': skillsFilterHidden}"> <input type="text" ng-model="skillQuery" ng-change="filterSkills()" placeholder="Filter skills" class="filter- ...

Prevent elements from displaying until Masonry has been properly set up

My goal is to merge Masonry elements with existing ones. Currently, the items appear before Masonry initializes then quickly adjust into position a moment later. I want them to remain hidden until they are in their proper place. This is the snippet (with ...

Utilizing useEffect Hooks to Filter Local JSON Data in React Applications

For my engineering page, I have been developing a user display that allows data to be filtered by field and expertise. Fields can be filtered through a dropdown menu selection, while expertise can be filtered using an input field. My initial plan was to ...

The Express server automatically shuts down following the completion of 5 GET requests

The functionality of this code is as expected, however, after the fifth GET request, it successfully executes the backend operation (storing data in the database) but does not log anything on the server and there are no frontend changes (ReactJS). const ex ...

Leveraging the power of context to fetch data from a store in a React component within the Next

I'm having trouble with the title in my React project, and I'm new to React and Nextjs. When trying to fetch data from my dummy chat messages, I encountered this error: × TypeError: undefined is not iterable (cannot read property Symbol(Sy ...

Having difficulty with a script not functioning properly within an onclick button

In my script, I am using the following code: for (var i in $scope.hulls) { if ($scope.hulls[i].id == 1234) { console.log($scope.hulls[i]); $scope.selectedHullShip1 = $scope.hulls[i]; } } The code works fine outside of the onclick button, but fails to run ...

JOLT specification for transforming a deeply nested JSON into a flattened JSON format

Seeking assistance on the Jolt specification needed to convert a nested JSON structure into a denormalized JSON. Input: { header : company: "ABC", ip: 10.3.2.4, network : [ {url:"http://abc.in", "latency":2000}, {url:"http://xzy.au", "l ...

I'm experiencing difficulties loading data using AJAX

I'm facing an issue with an old script that used to load IP from an xml file. Everything was running smoothly until about six months ago when I tried to use it again and encountered some problems. I'm not sure what went wrong. Could there have be ...

Convert a collection of whole numbers into JSON structure

Is it possible to represent a list of numbers in JSON format for passing data to a web API using Postman? List<int> items = new List<int>(); items.Add(1006); items.Add(1007); Would like some advice on how to properly represent the numbers in ...

Issues encountered with JS and PHP are causing $_GET['example'] to malfunction at the moment

Recently, I developed a JavaScript system to load pages into a default div called PageContent. However, I encountered an issue when trying to utilize the PHP $_GET function alongside my JS setup. It appears that my JavaScript code is preventing the URL var ...

Combining Arrays in AngularJS with an owl-carousel Setting

My goal is to implement an endless scrolling carousel in AngularJS using owl-carousel. The idea is to load new items every time the carousel is fully scrolled and seamlessly merge queried elements with the existing list. However, I've encountered a pr ...

powershellUsing the cURL command with a PHP script

I am having trouble sending JSON data from the command line with curl to a php script and properly receiving it on the server-side. Here is what I have attempted so far: Running the following command in the command line: curl -H "Content-Type: applicati ...

Display/hide a div containing distinct content

Upon clicking an image in the carousel, a position: absolute; div should appear containing two different images and a form related to the initial picture clicked with a submit button. How can I implement a show/hide feature that displays unique content for ...

Stop a hacker from obtaining the usernames from a system

Our forgot password page has been identified with a security issue that needs attention: ISS-0003938 Web Inspect Open Medium Suspicious Files Found in Recursive Directory ****** Remove any unnecessary pages from the web server If any files are nec ...

Processing JSON data by reading multiple files using Node.js

I've encountered a situation where I have multiple files containing data with time stamps. It's important for me to read these files in order, line by line. However, I noticed that most Node packages utilize asynchronous methods for file reading. ...