php - Double display of some data from the laravel database
Get the solution ↓↓↓I have a strange problem, I went through the elements of the database with a foreach, but when I display in another page, instead of seeing me only one question from the database, I display two, from what is it? Is it running twice? https://i.imgur.com/EfmqKB1.png
Route:
Route::get('/home', 'PostsController@viewPosts')->name('home');
Route::get('/viewUserQuestion/{post}', 'PostsController@viewUserQuestion')->name('viewQuestion');
Controller:
public function viewPosts() {
$posts = Post::latest()->get();
return view('home', compact('posts'));
}
public function viewUserQuestion() {
$posts = Post::latest()->get();
return view('viewQuestion', compact('posts'));
}
View:
@extends('layouts.app') @section('content')
<div class="card-body p-0">
@csrf
@foreach($posts as $post)
<div class="mailbox-read-info">
<h5 align="center"> {{ $post->title }}</h5>
<h6> From userID: {{ $post->user_id }}</h6>
<span class="mailbox-read-time" align="center">Created at: {{ $post->created_at }}</span></h6>
</div>
<div class="mailbox-read-message">
<p>{{ $post->content }}</p>
Share solution ↓
Additional Information:
Link To Answer People are also looking for solutions of the problem: cannot set properties of undefined (setting '_dt_cellindex')
Didn't find the answer?
Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.
Similar questions
Find the answer in similar questions on our website.
Write quick answer
Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.