- Düzenlendi
Twitter yorum yapısını yapmak istedim başta iyiydi fakat atılan yorumun içine girmek istediğimde hata alıyorum (404).
buna girdiğimde şöyle bir şey geliyor
Atıllan yorumun urlsi şöyle
Database yapım şöyle
https://prnt.sc/RXZEUmdigCL-
Route
Route::get('/{user:username}/status/{tweet:id}', [TweetsController::class, 'show'])->name('tweet.show');
<Link :href="tweetLink(comment.user.username, comment.tweet_id)">
<div class="text-sm text-normalWhite">
{{ comment.body }}
</div>
</Link>
public function show(User $user,Tweet $tweet, Request $request) {
$comments = $tweet->comments()->with('user')->latest()->get();
$tweetStats = [
'likes_count' => $tweet->likes()->count(),
'liked' => $tweet->likes()->where('user_id', auth()->id())->exists(),
'tweet_view_count' => $tweet->tweet_view()->count(),
'comments_count' => $tweet->comments()->count(),
];
if (!Cookie::has('viewed_posts')) {
$viewedPosts = [];
} else {
$viewedPosts = json_decode(Cookie::get('viewed_posts'), true);
}
if (!in_array($tweet->id, $viewedPosts)) {
TweetView::create([
'ip_address' => $request->ip(),
'user_agent' => $request->userAgent(),
'tweet_id' => $tweet->id,
'user_id' => $request->user()?->id,
]);
$viewedPosts[] = $tweet->id;
Cookie::queue('viewed_posts', json_encode($viewedPosts), 60 * 24 * 365);
}
return Inertia::render('detail', [
'tweet' => $tweet->load('user'),
'tweetStats' => $tweetStats,
'comments' => $comments,
]);
}
class Comment extends Model
{
use HasFactory;
protected $guarded = [];
public function tweet() {
return $this->belongsTo(Tweet::class);
}
public function user() {
return $this->belongsTo(User::class, 'user_id');
}
}
Tweet
public function comments(): HasMany
{
return $this->hasMany(Comment::class);
}
Bence twitter id alıyor fakat ben yorumu comments de body içinde tutuyorum o yüzden sorun oluyor. Peki bunu farklı nasıl yapabilirdim.