#NotFoundHttpException in RouteCollection.php line 161

40 messages · Page 1 of 1 (latest)

undone zephyr
#

I don't know why my route isn't working?

My routes file is quite big, here is the chunk where this particular route is used:

routes.php:

// INVENTORY
  Route::get('parts-room/inventory/{part_number}/assigned', 'PartInventoryController@assigned');
  Route::get('parts-room/inventory/{part_number}/available', 'PartInventoryController@available');
  Route::get('parts-room/inventory/{part_number}/order-history', 'PartInventoryController@orderHistory');
  Route::get('parts-room/inventory/', 'PartInventoryController@index');
  Route::get('parts-room/inventory/{part_number}/details/{tracking-number}', 'PartInventoryController@show');
  Route::get('parts-room/inventory/{part_number}/edit/{tracking-number}', 'PartInventoryController@edit');

It's the /details route that doesn't work, all the others do.

here's my PartInventoryController@show:

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show(PartInventory $inventory, $part_number, $tracking_number)
    {
        dd($part_number, $tracking_number);
    }

I don't think the method is getting called, because it's returning an error and not the dumped data.

weary tapir
#

Why are you injecting PartInventory when it's not part of the route

php artisan route:list --path=parts-room

undone zephyr
#

I had all the code written inside the method, expecting the route to land there, and it was using that injection

#

for now I've pulled all the code and left something simple in order to verify the route is working

weary tapir
#

Your URI is parts-room/inventory/{part_number}/details/{tracking-number}, where is the inventory parameter here

undone zephyr
#

I'm not sure what you mean...there is no "inventory" parameter, that's just part of the URL path

#

are you talking about the "PartInventory $inventory" part in the show method?

weary tapir
#

Yes.

#

Your URI has 2 parameters, but your method has 3

undone zephyr
#

Oh. That's...what's the word for it...it's type hinting the model into the method

#

I learned a lot of what I know from Laracasts, and that's how Jeffery teaches it, I just forgot what he calls it

weary tapir
#

But it's not binding to anything

#

Route model binding

undone zephyr
#

Not yet. It did with the code that I created for the show method

weary tapir
#

/stuff/{inventory} -> method(Inventory $inventory)

undone zephyr
#

Here's my inventory index.blade.php, showing what I normally do with it:

#
public function index(PartInventory $inventory, PurchaseOrderLineItem $purchase_order_line_items, MasterPartNumber $master_parts)
    {
        $master_part_numbers = $master_parts->whereHas('parts_inventory', function($query){
                    $query->where('status', 1);
                })->with('parts_inventory')->orderBy('part_number')->get();

        $purchase_order_line_items = $purchase_order_line_items->all();
        
        return view('parts-room.inventory.index', compact('master_part_numbers', 'purchase_order_line_items'));
    }
#

This one is still a work in progress, but you can see how I'm normally using that route model binding

#

anyways, if I remove that bit I still get the error

weary tapir
#

php artisan route:list --path=parts-room

undone zephyr
#
POST     | parts-room/inventory/{part_number}/assign                    |                                             | pams\Http\Controllers\PartInventoryAssignmentController@assign     | auth       |
|        | GET|HEAD | parts-room/inventory/{part_number}/assigned                  |                                             | pams\Http\Controllers\PartInventoryController@assigned             | auth       |
|        | GET|HEAD | parts-room/inventory/{part_number}/available                 |                                             | pams\Http\Controllers\PartInventoryController@available            | auth       |
|        | GET|HEAD | parts-room/inventory/{part_number}/details/{tracking-number} |                                             | pams\Http\Controllers\PartInventoryController@details              | auth       |
|        | GET|HEAD | parts-room/inventory/{part_number}/edit/{tracking-number}    |                                             | pams\Http\Controllers\PartInventoryController@edit                 | auth       |
|        | GET|HEAD | parts-room/inventory/{part_number}/order-history             |                                             | pams\Http\Controllers\PartInventoryController@orderHistory         | auth       |
|        | POST     | parts-room/inventory/{part_number}/transfer                  |                                             | pams\Http\Controllers\PartInventoryBaseTransferController@transfer | auth       |
#

oh...that didn't paste well

#

I narrowed it down a little from your search, I added /inventory

weary tapir
#

Well it's critical you look from the root of the URI in case you have other routes that contradict each other

undone zephyr
#

I changed the name of the route from show to details as we've been chatting, to try and troubleshoot it

#

(BTW)

weary tapir
#

If you edit the @methodName you need to do that in the controller too.

Also I believe your issue comes from the way you name the parameters, some are with _ and others with - and I don't even think - works? You can't have variables named $something-test. Idk if Laravel changes it to $somethingTest behind the scenes, probably does... But you should not mix naming conventions in your app regardless, and especially not use _

undone zephyr
#

All my parameters are underscored, it's just the url name that has a dash

#

OHHHHH

weary tapir
#

Bro

undone zephyr
#

DING DING DING!!

weary tapir
#

You shouldn't mix and match, there's a reason why the docs instruct you to have your URI parameters named the same as the variables in the controller, so it can map it

undone zephyr
#

I didn't realize I had a dash in the tracking numbers parameter

#

That fixed my problem, thank you!

weary tapir
#

You should probably stick to PSR stating you should do camelCasing and PascalCasing

#

$my_variable is a smelly one from $myVariable

undone zephyr
#

yes, you're right, I should.

#

This is actually a legacy product that I'm maintaining until v2.0 is complete

#

So, I've recognized some of my errors along the way, and I don't do that anymore, but I'm not going to go back and change it in an old project

#

thank you though 🙂