1

Imagine you want to filter a table results you would do something like:

public function users(Request $request) {
    if ($request()->has('gender')) {
      $users = User::where('gender', request('gender'))
      ->paginate(5)
      ->appends('gender', request('gender'));
    } else {
      $users = User::->get();
    }
    return view('front.users', compact('users'));
  }

and it works just fine.

But in my case I try to filter my orders base on integer column which provides status of orders named orderstatus_id.

public function orders(Request $request) {
    if ($request()->has('orderstatus_id')) {
      $orders = Order::where('user_id', '=', Auth::user()->id)
      ->where('orderstatus_id', request('orderstatus_id'))
      ->paginate(5)
      ->appends('orderstatus_id', request('orderstatus_id'));
    } else {
      $orders = Order::where('user_id', '=', Auth::user()->id)->get();
    }
    return view('front.orders', compact('orders'));
  }

the problem is i get this error:

Function name must be a string

on this part:

if ($request()->has('orderstatus_id')) {

Any idea?

1 Answer 1

2

Change this:

$request()

To this, if you want to use the global helper:

request()

Or to this:

$request

Both will do the same job.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.