dan3460
6 months ago

Resource route not taking parameter

Posted 6 months ago by dan3460

I have a weird problem that i don't know how to troubleshoot. I have a button with to edit an order, that hits the:

Route::resource('orders', 'OrdersController');

which goes to:

public function edit(Orders $orders)
{
    dd($orders);
    $customer = Customer::find($orders->customer_id);
    $equipments = Equipment::where('customer_id',$orders->customer_id)->get();
    $techs = User::where('tech',true)->get();

    return view('orders.edit', compact('orders','customer','equipments','techs'));
}

the dd there gives me an empty collection:

Orders {#1181 ▼
  #table: "orders"
  #connection: null
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  #perPage: 15
  +exists: false
  +wasRecentlyCreated: false
  #attributes: []
  #original: []
  #changes: []
  #casts: []
  #dates: []
  #dateFormat: null
  #appends: []
  #dispatchesEvents: []
  #observables: []
  #relations: []
  #touches: []
  +timestamps: true
  #hidden: []
  #visible: []
  #fillable: []
  #guarded: array:1 [▶]
}

but if i do this:

Route::get('/orders/{order}/edit', function(Orders $order){
    dd($order);
});

returns the order:

Orders {#1188 ▼
  #table: "orders"
  #connection: "mysql"
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  #perPage: 15
  +exists: true
  +wasRecentlyCreated: false
  #attributes: array:12 [▼
    "id" => 1
    "customer_id" => 32
    "equipment_id" => null
    "users_id" => null
    "date" => "2019-05-21 00:00:00"
    "update" => null
    "invoiced" => 0
    "notes" => null
    "warning" => null
    "created_by" => 1
    "created_at" => "2019-05-21 20:58:47"
    "updated_at" => "2019-05-21 20:58:47"
  ]
  #original: array:12 [▶]
  #changes: []
  #casts: []
  #dates: []
  #dateFormat: null
  #appends: []
  #dispatchesEvents: []
  #observables: []
  #relations: []
  #touches: []
  +timestamps: true
  #hidden: []
  #visible: []
  #fillable: []
  #guarded: array:1 [▶]
}

Where i can see what is being passed in the resource route?

Please sign in or create an account to participate in this conversation.