A
A
Alexey2019-02-19 02:54:23
Laravel
Alexey, 2019-02-19 02:54:23

How to display news preview on the page?

there is this code

@if (count($posts)>0)
    @foreach ($posts as $post)
    <article class="shnews clearfix">
        <div class="short-in">
            <div class="sh-desc">
                <a href="{{route('front.news', $post->slug)}}"><div class="sh-title">{{$post->title}}</div></a>

                <div class="sh-orgtitle">
                    <span style="width: 110px">
                        <i class="fa fa-clock-o"></i> {{ App::make("HelperController")->formateCreationDate($post->created_at) }}&nbsp;&middot;&nbsp;
                    </span>
                    <span><i class="fa fa-user"></i> {{$post->user->username}}</span>

                @if(!is_null($post->manga))
                        <span>&nbsp;&middot;&nbsp;<i class="fa fa-folder-open-o"></i> {{ link_to_route('front.manga.show', $post->manga->name, $post->manga->slug) }}</span>
                @endif
                </div>
        
            </div>
        </div>
  </article>
    @endforeach

It is displayed on the news page, but on the main page there is a similar code along with a box of
the following format:
<div class="floats clearfix">
        @foreach ($mangaNews as $post)
            <?php

                preg_match('#<img[^>]*src="([^"]+)"#Uiu', $post->content, $match);
                if (count($match)) $img = $match[1];
                else $img = '';

            ?>

            <article class="short shnews clearfix" id="short">
                <div class="short-in">
                    <div class="sh-desc">
                        <a href="{{route('front.news', $post->slug)}}"><div class="sh-title">{{$post->title}}</div></a>
                    </div>
                    <a class="short-poster img-box" href="{{route('front.news', $post->slug)}}">
                        @if ($img) <img src="{{ $img }}"/> @endif
                        <div class="short-meta short-label sl-y">
                            <span style="width: 110px">
                                <i class="fa fa-clock"></i> {{ App::make("HelperController")->formateCreationDate($post->created_at) }}
                            </span><br/>
                            <span><i class="fa fa-user"></i> {{$post->user->username}}</span><br/>
                            @if(!is_null($post->manga))
                                <span>&nbsp;<i class="fa fa-folder-open-o"></i> {{ link_to_route('front.manga.show', $post->manga->name, $post->manga->slug) }}</span>
                            @endif
                        </div>
                    </a>
                </div>
            </article>
        @endforeach
    </div>
    @endif

tried to put from the main to the news page
<a class="short-poster img-box" href="{{route('front.news', $post->slug)}}">
                        @if ($img) <img src="{{ $img }}"/> @endif

immediately after displaying the name of the news but in this case I got an error, I already tried all the possible options, but as I understand it, it doesn’t work the same way as on the main page, it doesn’t display the news page. tell me how to prescribe what would display =_= the brain is already boiling @if ($img) <img src="{{ $img }}"/> @endif

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question