停用后,帖子无法正确显示

时间:2019-09-20 10:38:06

标签: php html laravel

因此,我在显示几则帖子时遇到了问题。在取消激活帖子后,main不再显示,但是即使我处于@if条件,该空间仍在这里。默认情况下,在我的页面上,每页上有7个帖子,但是这里仅剩下已激活的帖子(表event,列activate

这是来自main的代码

    <div class="clearfix margin-bottom-20"><hr></div>

                <!-- News v3 -->
                @foreach($events as $event)
        @if($event->active != 1)
                    <div class="row margin-bottom-20">
                        <div class="col-sm-5 sm-margin-bottom-20">
                            <div class="easy-block-v1">
                                <a href="{{ url('topic') }}/{{ $event->category->category_url }}">
                                    <div class="easy-block-v1-badge rgba-{{ $event->category->color }} noticeboard-topic-category">
                                        <i class="icon-hotel-restaurant-183 u-line-icon-pro fa-"></i> / {{ $event->category->category }}
                                    </div>
                                </a>


                                <?php
                                    $video_content = preg_replace("/<img[^>]+\>/i", "", $event->information);
                                    preg_match('/src="([^"]+)"/', $video_content, $video);
                                ?>

                                <?php
                                    $match = '';
                                    $str = $event->information;
                                    $start = "<iframe src='";
                                    $end = "' width='100%' height='281'></iframe>";

                                    $pattern = sprintf(
                                        '/%s(.+?)%s/ims',
                                        preg_quote($start, '/'), preg_quote($end, '/')
                                        );

                                    if (preg_match($pattern, $str, $matches)) {
                                        list(, $match) = $matches;
                                    }
                                ?>
                                @if(isset($match) && $match != '')
                                    <iframe src="{{ $match }}" width='100%' height='250'></iframe>
                                @elseif(isset($video[1]))
                                    <iframe src="{{ $video[1] }}" width='100%' height='250'></iframe>
                                @else

                                    <?php preg_match('/<img.+src=[\'"](?P<src>.+?)[\'"].*>/i', $event->information, $image); ?>
                                    @if(isset($image['src']))
                                        <!-- <img class="img-responsive" src="{{ $image['src'] }}" alt=""> -->

                                        <?php $img = str_replace('&amp;', '&', $image['src']); ?>
                                        <img class="img-responsive" src="{{ url('ass/336/212?'.$img) }}" alt="">
                                    @else

                                        <?php $img = "thumbnail/".$event->user->profile_picture; ?>
                                        @if(@getimagesize($img))
                                            <img src="{{ url('ass/336/212?'.$img) }}" alt='' />
                                        @else
                                            <?php $img = "assets/img/main/img12.jpg"; ?>
                                            <img class="img-responsive" src="{{ url('ass/336/212?'.$img) }}" alt="">
                                        @endif
                                    @endif
                                @endif
                            </div>




                        </div>
                        <div class="col-sm-7 news-v3">
                            <div class="news-v3-in-sm no-padding">

                                <h2><a href="{{ url('view-event') }}/{{ $event->id }}_{{ Slugify::slugify($event->subject) }}">{{ $event->subject }}</a></h2>
                                <ul class="list-inline" style="right: 10px;position: relative">

                                    <li style="font-style: normal !important">
                                    <li style="font-style: normal !important">



                                    @if($event->user->role[0]->pivot->role_id == 1)
                                    <i style="margin-right: 2px;margin-left: 3px;font-size: 11px" class="icon-user"></i>
                                    @else
                                    <i style="margin-right: 2px;margin-left: 3px;font-size: 11px" class="icon-hotel-restaurant-172 u-line-icon-pro fa- fa-lg"></i>
                                    @endif
                <a style="margin-left: 2px" href="{{ url('') }}/{{ $event->user->username }}">{{ $event->user->username }}</a></li>
                                    <li style="font-style: normal !important"><i style="margin-right: 3px" class="icon-hotel-restaurant-183 u-line-icon-pro fa-"></i> <a href="{{ url('view-all-event') }}">Event</li>

                                    <li style="font-style: normal !important"><i style="margin-right: 3px" class="icon-notebook fa-"></i> <a href="{{ url('topic') }}/{{ $event->category->category_url  }}">{{ $event->category->category }}</a></li>
                                                                    </ul>
                                <?php
                                    $information = preg_replace("/<img[^>]+\>/i", "", $event->information);
                                    $Output = preg_replace('/<iframe.*?\/iframe>/i','', $information);
                                ?>

                                <p>{{ str_limit(trim(strip_tags(preg_replace(array('/\s{2,}/', '/[\t\n]/'), ' ', $Output))), 200) }}</p>

                                <ul class="social-icons social-icons-color social-cu-icons" style="display:none;">
                                    <div class="social-cu">

                                        <li class="facebook_share share_link" link="{{ url('view-event') }}/{{ $event->id }}_{{ Slugify::slugify($event->subject) }}" name="{{ $event->subject }}" description="{{ $event->subject }}">
                                            <a href="#" data-original-title="Facebook" class="rounded social_facebook"></a>
                                        </li>

                                        <li class="google_share share_link" link="{{ url('view-event') }}/{{ $event->id }}_{{ Slugify::slugify($event->subject) }}" name="{{ $event->subject }}" description="{{ $event->subject }}">
                                            <a href="#" data-original-title="Google Plus" class="rounded social_googleplus"></a>
                                        </li>

                                        <li class="twitter_share share_link" link="{{ url('view-event') }}/{{ $event->id }}_{{ Slugify::slugify($event->subject) }}" name="{{ $event->subject }}" description="{{ $event->subject }}">
                                            <a href="#" data-original-title="Twitter" class="rounded social_twitter"></a>
                                        </li>

                                        <li class="whatapp_share share_link" link="{{ url('view-event') }}/{{ $event->id }}_{{ Slugify::slugify($event->subject) }}" name="{{ $event->subject }}" description="{{ $event->subject }}">
                                            <a href="whatsapp://send?text={{ url('view-event') }}/{{ $event->id }}_{{ Slugify::slugify($event->subject) }}">
                                                <img class="img-responsive social_whatsapp" src="{{ asset('/assets/img/icons/social/Whatsapp.png') }}" alt="">
                                            </a>
                                        </li>

                                    </div>


                                </ul>

                                <ul class="post-shares post-shares-lg">
                                    <li ><a href="#"><i class="rounded-x fa fa-comments-o  "><span>{!! $event->event_comment_count !!}</span></i></a></li>

                                    <li><a href="javascript:void(0)"><i class="rounded-x icon-magnifier-add" ><span>{!! $event->views !!}</span></i></a></li>

                                    <li class="changeview" value="{{ $event->id }}" id="changeview"><a href="javascript:void(0)" onClick="return loginConf();"><i class="rounded-x  icon-like "><span class="like_{{ $event->id }}">{!! $event->event_like_count !!}</span></i></a></li>

                                    <li class="share-link"><a href="javascript:void(0)"><i class="rounded-x icon-share"></i></a></li>

                                </ul>
                                <br>
                                <a href="{{ url('view-event') }}/{{ $event->id }}_{{ urlencode(str_replace(' ', '-', $event->subject)) }}">Read more...</a>
                            </div>
                        </div>
                    </div><!--/end row-->
                    <!-- End News v3 -->

                    <div class="clearfix margin-bottom-20"><hr></div>
          @endif
                @endforeach

我的控制器

public function viewAllEvent($category_id = null,$event_type_id = null,$country_id = null,$starting_date = null,$username = null,$search = null,$page = null)
    {

        // $eventrecommended = Event::with('user','category','country','event_type','event_like')->withCount('event_like','event_comment')->whereHas('user.contact', function ($query) use ($id) {
        //                 $query->where('contacts.user_id', '=', $id);
        //             })->orWhere('events.public', '=', 1)->orWhere('events.user_id', '=', $id);
        // if($page == ""){
        //     return redirect('view-all-event/1');
        // }

            $data = $this->data;

            $data['title'] = "View All Event";
            $data['breadcrumbs'] = "Events";

            $page = Input::get('page');
            $perPage = 7;
            $offset = ($page * $perPage) - $perPage;

            $data['evnetTypeList'] =  \App\EventType::all();
            $data['countryList'] = [''=>'Country'] + \App\Country::lists('country','code')->toArray();

            $data['category'] = Input::get('category');
            $data['event_type'] = Input::get('event_type');
            $data['country'] = Input::get('country');
            $data['starting_date'] = Input::get('starting_date');
            $username = Input::get('username');
            $search = Input::get('search');
            $data['login_user'] = $username;
            $data['search'] = $search;





            $categoryID =  \App\Category::pluck('id');


            $event = Event::with('user','category','country','event_type')->withCount('event_like','event_comment')->whereHas('user', function($query) {
                        $query->where('deleted_at', '=', null);
                    })->whereIn('category_id',$categoryID);



            $eventrecommended = Event::with('user','category','country','event_type','event_like')->whereHas('user', function($query) {
                    $query->where('deleted_at', '=', null);
                })->withCount('event_like','event_comment')->whereIn('category_id',$categoryID);


            if ($user = Sentinel::check())
            {
                if(!$user->inRole('admins'))
                {
                    $id = $user->id;

                    $event = $event->Where(function($query1) use($id){
                            $query1->where('public','=', 1)->orWhereHas('user.contact', function ($query) use ($id) {
                                $query->where('user_id', '=', $id);
                                })->orWhere('user_id','=',$id);
                    });

                    $eventrecommended = $eventrecommended->Where(function($query1) use($id){
                            $query1->where('public','=', 1)->orWhereHas('user.contact', function ($query) use ($id) {
                                $query->where('user_id', '=', $id);
                                })->orWhere('user_id','=',$id);
                    });
                }
            }
            else{
                $event = $event->where('public','=', 1);
                $eventrecommended = $eventrecommended->where('public','=', 1);

            }


            return view('event.view_all_event',$data);
    }

enter image description here enter image description here

第二张照片是我的布告栏,我也遇到同样的问题...

1 个答案:

答案 0 :(得分:1)

添加到您在控制器中的$event

where('active', 0)

并在您的视图中删除if语句

 @if($event->active != 1)
 @endif