ShanWave007
ShanWave007

Reputation: 361

Why the result of laravel eloquent incrementing always?

I try to execute select * from articles where category_id=1 in laravel eloquent model as below.

$articles = Article::where('category_id', '=', $id)->get();

And i pass this to my view file by using compact method as below.

return view('homeview.index', compact('articles'));

And i use this $articles variable in foreach loop and print each article's title in view file. But the thing is when i try to execute this, my view file is refreshing continuously and incrementing the same div class which i used to print the article titles. I tried to use above code as raw query also. It also generates the same issue.

below is my view file.

<tbody>
         @foreach($articles as $article)
            <tr>
                <td><img src="{{asset('/img_thumbs/'.$article->img_thumb)}}"></td>
                <td class="-align-center">
                <a href="{{action('ArticleController@show', [$article->id])}}"> <h4>{{$article->title}}</h4></a>
                <p>{{$article->sub_paragraph}}</p>
                      </td>
                   <tr>
            @endforeach
             </tbody> 

Please help me to solve this.

Upvotes: 2

Views: 72

Answers (2)

ShanWave007
ShanWave007

Reputation: 361

i used some java scripts for my application. That repeating thing happening because one script file. After i comment it, my page is working fine. I used some template called inspinia and it is happening because inspinia.js file.

Upvotes: 0

Unamata Sanatarai
Unamata Sanatarai

Reputation: 6647

The bottom line is, THere's an error in your HTML.

You are opening <tr> but not closing it.

<tbody>
         @foreach($articles as $article)
            <tr>
                <td><img src="{{asset('/img_thumbs/'.$article->img_thumb)}}"></td>
                <td class="-align-center">
                <a href="{{action('ArticleController@show', [$article->id])}}"> <h4>{{$article->title}}</h4></a>
                <p>{{$article->sub_paragraph}}</p>
                      </td>
                   </tr> <!-- HERE -->
            @endforeach
             </tbody> 

Upvotes: 0

Related Questions