Home > Backend Development > PHP Tutorial > Laravel点击页面链接按某一条件排序,这个页面的更新链接应该如何写?

Laravel点击页面链接按某一条件排序,这个页面的更新链接应该如何写?

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-06 20:23:01
Original
959 people have browsed it

如题。。一个图片的展示页面,如果我想根据某一条件排序,例如根据ID倒序排序,那么这个在blade.php的条件更新链接应该怎样写

<code>public function index()
    {
        $images = Image::paginate(10);
        return view('images-list',compact('images'));
    }</code>
Copy after login
Copy after login
<code>//想根据ID倒序,(请问这样的情况需要另外新开一个controller吗)
public function idsort()
    {
        $images = Image::paginate(10);
        $idsort = $images->sortByDesc('id');
        return view('test',compact('images','idsort'));
    }</code>
Copy after login
Copy after login
<code><!-- blade.php片段 -->
@forelse($images as $image)
         <div class="col-md-3 col-xs-6 col-sm-6">
            <div class="thumbnail">
               <img  src="%7B%7Basset(%24image->file)%7D%7D" alt="Laravel点击页面链接按某一条件排序,这个页面的更新链接应该如何写?" >
               <div class="caption">
                  <h5>{{$image->caption}}</h5>
                  <p>{!! substr($image->description, 0,100) !!}</p>
                  <p>
                     </p>
<div class="row text-center" style="padding-left:1em;">
                     <a href="%7B%7B%20url('/image/'.%24image->id.'/edit')%20%7D%7D" class="btn btn-warning pull-left">Edit</a>
                     <span class="pull-left"> </span>
                     {!! Form::open(['url'=>'/image/'.$image->id, 'class'=>'pull-left']) !!}
                        {!! Form::hidden('_method', 'DELETE') !!}
                        {!! Form::submit('Delete', ['class' => 'btn btn-danger', 'onclick'=>'return confirm(\'Are you sure?\')']) !!}
                     {!! Form::close() !!}
                     </div>
                  
               </div>
            </div>
         </div>
      @empty
         <p>No images yet, <a href="%7B%7B%20url('/image/create')%20%7D%7D">add a new one</a>?</p>
      @endforelse</code>
Copy after login
Copy after login

回复内容:

如题。。一个图片的展示页面,如果我想根据某一条件排序,例如根据ID倒序排序,那么这个在blade.php的条件更新链接应该怎样写

<code>public function index()
    {
        $images = Image::paginate(10);
        return view('images-list',compact('images'));
    }</code>
Copy after login
Copy after login
<code>//想根据ID倒序,(请问这样的情况需要另外新开一个controller吗)
public function idsort()
    {
        $images = Image::paginate(10);
        $idsort = $images->sortByDesc('id');
        return view('test',compact('images','idsort'));
    }</code>
Copy after login
Copy after login
<code><!-- blade.php片段 -->
@forelse($images as $image)
         <div class="col-md-3 col-xs-6 col-sm-6">
            <div class="thumbnail">
               <img  src="%7B%7Basset(%24image->file)%7D%7D" alt="Laravel点击页面链接按某一条件排序,这个页面的更新链接应该如何写?" >
               <div class="caption">
                  <h5>{{$image->caption}}</h5>
                  <p>{!! substr($image->description, 0,100) !!}</p>
                  <p>
                     </p>
<div class="row text-center" style="padding-left:1em;">
                     <a href="%7B%7B%20url('/image/'.%24image->id.'/edit')%20%7D%7D" class="btn btn-warning pull-left">Edit</a>
                     <span class="pull-left"> </span>
                     {!! Form::open(['url'=>'/image/'.$image->id, 'class'=>'pull-left']) !!}
                        {!! Form::hidden('_method', 'DELETE') !!}
                        {!! Form::submit('Delete', ['class' => 'btn btn-danger', 'onclick'=>'return confirm(\'Are you sure?\')']) !!}
                     {!! Form::close() !!}
                     </div>
                  
               </div>
            </div>
         </div>
      @empty
         <p>No images yet, <a href="%7B%7B%20url('/image/create')%20%7D%7D">add a new one</a>?</p>
      @endforelse</code>
Copy after login
Copy after login

已经看到这个问题多次了,这不叫更新,你只需要对查询时排序即可。

Eloquent ORM文档

<code>$users = User::popular()->women()->orderBy('created_at')->get();</code>
Copy after login
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Issues
php data acquisition?
From 1970-01-01 08:00:00
0
0
0
PHP extension intl
From 1970-01-01 08:00:00
0
0
0
How to learn php well
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template