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;
useApp\Http\Requests\CommentRequest;
use App\Comment;
use Auth;
class CommentsController extensions Controller
{
public function store (CommentRequest$request)
{
$comment = new comment;
$comment->comment=$request->comment;
$comment->user_id=Auth::id();
$comment->name=";
$comment->post_id=$request->post_id;
$comment->save();
return redirect()->route('bbs.show', [$comment['post_id']])->with('commentstatus', 'comment posted');
}
public function post()
{
return$this->belongsTo('App\Post');
}
public function user()
{
return$this->belongsTo('App\User');
}
public function up()
{
Schema::create('comments', function(Blueprint$table){
$table->bigIncrements('id');
$table->timestamps();
$table->string('is_deleted',4)->default('0');
$table->integer('post_id');
$table->string('name');
$table->text('comment');
$table->unsignedBigInteger('user_id');
$table->foreign('user_id')->references('id')->on('users');
});
}
@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}}
</time>
The user_id column is required in the comments table.
573 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
917 When building Fast API+Uvicorn environment with PyInstaller, console=False results in an error
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
620 Uncaught (inpromise) Error on Electron: An object could not be cloned
© 2024 OneMinuteCode. All rights reserved.