mardi 29 mars 2016

pagination totoal does not return 0 if there is no record in laravel 5

I have error in pagination total.

Actually I'm getting the results but the problem is when there is no records then it throws the following error: Undefined index: inactive_users (View: /home/vagrant/Code/krankontroll/resources/views/customer/inactive.blade.php)

If I don't have any records for inactive_users array I'm getting the above error where actually it should give "No of records 0".

My controller page code is:

$customers = Customer::getCustomerPaginated(Session::get('search'),     $data['sortorder'], $data['sortby']); 
$data['customers'] = Customer::getCustomerByStatus($customers, (Input::get('page'))?Input::get('page'):1);

And my model page code is:

public static function getCustomerByStatus($customers, $pageStart=1) 
{
    $customer_status = array();
    $customer_result = array();
    $newcustomers=array();
    foreach($customers as $customer){
        $customer_status[$customer->status][] = $customer;
        if($customer->status<>2)            
        $customer_status[3][] = $customer;
        $newcustomers[] = $customer;        
    }
    $customer_result = $customer_status;
    $perPage = 10;

    // Start displaying items from this number;
    $offSet = ($pageStart * $perPage) - $perPage;

    //Slice the collection to get the items to display in current page
    $currentPageSearchResults = $customers->slice($offSet, $perPage, true)->all();
    $collection = new Collection($currentPageSearchResults);

    // Get only the items you need using array_slice
    $pagination['all'] = new LengthAwarePaginator($collection, count($newcustomers), $perPage, Paginator::resolveCurrentPage(), array('path' => Paginator::resolveCurrentPath()));

    foreach($customer_status as $status=>$customer_state)
    {
        $itemsForCurrentPage = new Collection(array_slice($customer_state, $offSet, $perPage, true));
        if($status==0)
            $label='active_users';
        else if($status==1)
            $label='inactive_users';
        else if($status==3)
            $label='nonyearly_users';
        else
            $label='yearly_users';
            $pagination[$label] = new LengthAwarePaginator($itemsForCurrentPage, count($customer_state), $perPage, Paginator::resolveCurrentPage(), array('path' => Paginator::resolveCurrentPath()));
    }
    var_dump($pagination);
    exit;
    return $pagination;
}

Can anyone help me???



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1Uz8iNL
via IFTTT

Aucun commentaire:

Enregistrer un commentaire