Home >Backend Development >PHP Tutorial >Laravel 5.1分类排序

Laravel 5.1分类排序

WBOY
WBOYOriginal
2016-06-20 12:45:541141browse

其实排序很简单,就是将需要排序的ID和排序的值一一对应更新就OK了。

模板页面(index.blade.php)

{!! Form::open( array('url' => 'admin/category/sort/', 'method' => 'put') ) !!}@foreach($categories as $category){{--此处省略一些字段--}}<td><input class="sort" type="text" name="sort[]" value="{{$user_category ->sort}}"></td><input type="hidden" name="id[]" value="{{$user_category->id}}">@endforeach<div class="btn-group pull-left btn-sort">    <button class="btn btn-block btn-primary" type="submit">排序</button></div>{!!Form::close()!!}

控制器:

public function sort(Request $request)    {        $sorts = Input::get('sort');        $ids = Input::get('id');        foreach($sorts as $index => $sort){            $id = $ids[$index];            $st = Category::find($id);            $st->update([                'sort' => $sort            ]);        }        return redirect('admin/category')->with('message', '排序成功!');    }

路由:

Route::put('category/sort','CategoryController@sort');

如图:

原文:http://note.mango.im/article/29

Statement:
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