dimanche 24 janvier 2016

Laravel pagination is not working in case of sorting

In laravel,I trying to do sorting . In the fist page it's correct, But I turned to next page, I got is wrong wrong esult. Controller is

public function adminIndex(){
        /* Collect all cargo categories*/
        $allowed_columns=['id','name','status','updated_at'];
        $sort = in_array(Input::get('sort'),$allowed_columns) ? Input::get('sort'):'id';
        $order = empty(Input::get('order'))?'asc':Input::get('order');

        $cargo_categories =  CargoCategory::orderBy($sort,$order)
                    ->select('cargo_categories.id', 'cargo_categories.name', 'cargo_categories.status', 'cargo_categories.updated_at')
                    ->paginate(config('custom.pagination_size'));       
        $order = Input::get('order') ==='desc' ? 'asc':'desc';                  
        $statuses   = config('custom.statuses');

        return view('admin.cargo_categories.index', ['cargo_categories' => $cargo_categories, 'statuses' => $statuses,'sort'=>$sort,'order'=>$order]);
    }


View page is

 {!! $cargo_categories->render() !!}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire