Support the ongoing development of Laravel.io →
Database Eloquent Blade
Last updated 2 years ago.
0
  1. Fix your post code formatting if you expect some help
  2. @foreach ($news as $news)? Seriously? Change it to this
@foreach ($news as $item)

and reference $item variable inside foreach loop

Last updated 9 years ago.
0

You wrong foreach in view

Please use as @TorchSK

For post code, you can read this link

http://laravel.io/forum/01-31-2014-how-to-mark-up-forum-posts

Last updated 9 years ago.
0

this solved the problem with error

@foreach ($news as $item)

thanks. Now pagination works for news index page, but it is still not work for news item page. No error, but no pagination links.

0

Are you sure that this query returns more than one news item?

$news = News::where('sef', '=', $title)->orderBy('created_at', 'desc')->paginate(1);
0

you are right where('sef', '=', $title) should strict to only one item result.

0

I did this for my last project

NewsController.php


class NewsController extends Controller {

	public function showItem($title)
	{
		$news = News::where('sef', '=', $title)->get();

			foreach ($news as $news) // access user properties here
			{	
        		$previous = News::where('id', '<', $news->id)->orderBy('id', 'desc')->firstOrFail();
				$next = News::where('id', '>', $news->id)->orderBy('id', 'asc')->firstOrFail();
			}

		return view('news.item')
					->withNews($news)
					->withPrevious($previous)
					->withNext($next);
	
	}

}

\resources\views\news\item.blade.php

@extends('layout.main')

@foreach ($news as $news)


@section('title')
{{ $news->metatitle }}
@stop

@section('keywords')
{{ $news->metakey }}
@stop

@section('description')
{{ $news->metadesc }}
@stop



@section('content')



	<article>

        <i class="fa fa-calendar text-primary"> {{ date('d M Y', strtotime($news->created_at)) }} </i>
        <h1 class="page-header margin-0">{{ $news->title }}</h1>


       	<div class="page-content">
       	{{ HTML::image($news->image, $alt = $news->title, array('class' => 'thumbnail img-responsive pull-left')) }}
       	<div class="fulltext">{{ $news->fulltext }} 
         </div>
       	<div class="clearfix"></div>
       	</div>


    </article>

@endforeach


<ul class="pager">
@if (isset($previous) and $previous->category_id === $news->category_id )
<li class="previous"><a href="{{ $previous->sef }}">← Пред новость</a></li>
@endif

<li><a href="/news">&uarr; Наверх</a></li>

@if (isset($next) and $next->category_id === $news->category_id )
<li class="next"><a href="{{ $next->sef }}">След новость →</a></li>
@endif
</ul>


@stop
0

i am also searching for this bit dn't get any help

0

Sign in to participate in this thread!

Eventy

Your banner here too?

schel4ok schel4ok Joined 15 Feb 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.