@foreach ($news as $item)
and reference $item variable inside foreach loop
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
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.
Are you sure that this query returns more than one news item?
$news = News::where('sef', '=', $title)->orderBy('created_at', 'desc')->paginate(1);
you are right where('sef', '=', $title) should strict to only one item result.
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">↑ Наверх</a></li>
@if (isset($next) and $next->category_id === $news->category_id )
<li class="next"><a href="{{ $next->sef }}">След новость →</a></li>
@endif
</ul>
@stop
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community