0

I am trying to run the query below but I keep getting null return.

$result = Order::with(['customers', 'team'])->where('customers_id','=', $custid)->select(sprintf('%s.*', (new Order)->table));

Then I changed it to

$result = Order::with(['customers', 'team'])->where(function($query) use ($cust) {$query->where('customers_id', $cust);})->select(sprintf('%s.*', (new Order)->table));

still returns null.

customers_id belongs to the orders table and references the customer's table. I am getting the $custid from the URL parameter.

If I replace $custid with an integer for example 3, it returns all orders for the customer with id 3. I have spent hours trying to resolve the issue. I have hosted on Heroku and localhost but nothing works.

2
  • Include the code you use to get $custid. Commented May 21, 2020 at 3:08
  • This is a url parameter I have this in the datatablesactions.blade a button href="{{ route('admin.orders.index', ['cid' => $row->id]) }} then in my orderscontroller@index $cust = $request->cid; Then this is the output of the querylog select count(*) as aggregate from (select '1' as row_count from orders where (customers_id is null) and orders.deleted_at is null) count_row_table [] select orders.* from orders where (customers_id is null) and orders.deleted_at is null [] Commented May 21, 2020 at 3:37

1 Answer 1

1

Your problem is the way you're getting the url parameter. Put your url parameter in your method declaration.

Check the Laravel docs under Dependency Injection & Route Parameters here

public function index(Request $request, $custid) {

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.