Show the name of the commented user

Asked 5 months ago, Updated 5 months ago, 14 views

I would like to display the name of the user who posted the comment.
Comments can be displayed, but the name of the contributor cannot be displayed.
Try changing the migration file method and type
I looked up articles about the comment function and related articles, but I couldn't find them.


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Comment; 
use Auth; 

class CommentsController extensions Controller
    public function store (CommentRequest$request)
        $comment = new comment;
        return redirect()->route('', [$comment['post_id']])->with('commentstatus', 'comment posted');


public function post()

    public function user()


public function up()
        Schema::create('comments', function(Blueprint$table){


@forelse($post->comments as $comment)
                    <div class="border-top p-4">
                        <time class="text-secondary">
                            {{ $comment->user->name}}/ Where to display the name
                            {{ optional($comment->created_at)->format('Y.m.d H:i')}}/ 
                            {{ optional($comment)->id}}

php laravel

2022-09-30 11:09

1 Answers

The user_id column is required in the comments table.

2022-09-30 11:09

If you have any answers or tips

© 2023 OneMinuteCode. All rights reserved.