Laravel Click the page link to sort by a condition, how should the update link of this page be written?

Source: Internet
Author: User
Tags compact
Title.. A picture of the display page, if I want to sort by a condition, for example, according to the order of the reverse ID, then the blade.php How the conditional update link should be written

public function index()    {        $images = Image::paginate(10);        return view('images-list',compact('images'));    }
//想根据ID倒序,(请问这样的情况需要另外新开一个controller吗)public function idsort()    {        $images = Image::paginate(10);        $idsort = $images->sortByDesc('id');        return view('test',compact('images','idsort'));    }

  
   @forelse($images as $image)                                    file)}}" />                                 

{{$image->caption}}

{!! substr($image->description, 0,100) !!}

id.'/edit') }}" class="btn btn-warning pull-left">Edit {!! 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() !!}

@empty

No images yet, add a new one?

@endforelse

Reply content:

Title.. A picture of the display page, if I want to sort according to a certain criteria, for example, according to the order of the reverse ID, then the blade.php conditional update link should be how to write ?

public function index()    {        $images = Image::paginate(10);        return view('images-list',compact('images'));    }
//想根据ID倒序,(请问这样的情况需要另外新开一个controller吗)public function idsort()    {        $images = Image::paginate(10);        $idsort = $images->sortByDesc('id');        return view('test',compact('images','idsort'));    }
 !--blade.php fragment--> @forelse ($images as $image) File)}} "/> {{$image->caption}} 

{!! substr ($imag E->description, 0,100)!}

ID. ' /edit ')}} "class=" btn btn-warning pull-left ">edit {!! Form::open ([' url ' = '/image/'. $image->id, ' class ' = ' Pull-left '])! {!! Form::hidden (' _method ', ' DELETE ')! {!! Form::submit (' Delete ', [' class ' = ' btn btn-danger ', ' onclick ' = ' return confirm (\ ' is You sure?\ ') ')! {!! Form::close ()!!}

@empty

No Images Yet, add a new one?

@endforelse

Have seen this problem many times, this is not called update, you just need to sort the query.

Eloquent ORM Documentation

$users = User::popular()->women()->orderBy('created_at')->get();
  • Related Article

    Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.