Skip to content
Advertisement

Laravel does not show all the available results from table

I am working with Laravel 8 to develop online ordering project and in this project, I want to show all the orders from orders table if the status of each order is set to awaiting, so here is my code:

public function awaiting()
    {
        $orders = Order::with('user')->where('status', 'awaiting')->whereHas('user')->latest()->paginate(20);
        return view('admin.orders.awaiting', compact('orders'));
    }

But now the problem is, it only shows the first result from table, however there are more than one record stored at orders table.

How can I fix this issue?

UPDATE #1:

enter image description here

Advertisement

Answer

The issue is with second record in db .It has white space awaitingrn in at the end of string .

I suggest you to create separate table for status and then reference status id in order table to avoid these type of errors

So better before saving to db trim it by defining a Mutator

   public function setStatusAttribute($value)
    {
    
      
            $this->attributes['status'] = Str::of($value)->trim();
            
    }

Ref:https://laravel.com/docs/8.x/eloquent-mutators#defining-a-mutator Ref:https://laravel.com/docs/8.x/helpers#method-fluent-str-trim

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement