I'm running into a frustrating problem with routing in the Laravel app that I'm working on. The TL/DR of the issue is simply that the routes that go to an index are failing to show the associated index.blade.php view. Here is the route that I am currently working on:
// Business Owner Routes
Route::prefix('businesses')->middleware(['auth', 'verified'])->name("businesses.")->controller(OwnerController::class)->group(function () {
Route::get('owners', 'index')->name('owners.index');
Route::get('owners/create/{businessId}', 'create')->name('owners.create');
Route::post('owners', 'store')->name('owners.store');
Route::get('owners/edit/{owner}', 'edit')->name('owners.edit');
Route::put('owners/{owner}', 'update')->name('owners.update');
Route::delete('owners/{owner}', 'destroy')->name('owners.destroy');
});
It's an important note, that the store, edit, update, and destroy methods are all working. So we really are focusing on why the index route/method is not firing correctly.
The target blade file should respond to the named route: businesses.owners.index
The file is located in resources\views\businesses\owners and is named index.blade.php
Here is the OwnerController's index method:
public function index()
{
return view('businesses.owners.index', [
'owners' => Owner::paginate(5),
]);
}
When I check the artisan route:list, I see that the route is listed accurately.
GET|HEAD businesses/owners ................. businesses.owners.index > OwnerController@index
Things I have tried to correct the issue:
- Cleared the routing cache with
php artisan route:clear
- Used dd() inside the index method of the OwnerController: This did not get executed indicating that it is not even hitting the index method.
- Verified that I included the controller in the web.php file
use App\Http\Controllers\OwnerController;
- Verified that the mod_rewrite.c module was enabled and running on my apache web server
- Removed middleware group to see if the auth or verified middleware groups were causing an issue
- Attempted to write the route outside of the grouping. (Same, 404 Not Found for route)
Route::get('/businesses/owners', [OwnerController::class, 'index'])->middleware(['auth', 'verified'])->name('businesses.owners.index');
- Attempted to duplicate the issue in a different route grouping using a different controller:
// Billing Address Routes
Route::prefix('customers')->middleware(['auth', 'verified'])->name('customers.')->controller(BillingAddressController::class)->group(function () {
Route::get('billing-addresses', 'index')->name('billing-addresses.index');
Route::get('billing-addresses/create/{customerId}', 'create')->name('billing-addresses.create');
Route::post('billing-addresses', 'store')->name('billing-addresses.store');
Route::get('billing-addresses/edit/{billingAddress}', 'edit')->name('billing-addresses.edit');
Route::put('billing-addresses/{billingAddress}', 'update')->name('billing-addresses.update');
Route::delete('billing-addresses/{billingAddress}', 'destroy')->name('billing-addresses.destroy');
});
Note: This yielded the same issue. All routes worked except the index route of the controller.
- Verified my controller was using
use Illuminate\View\View;
I'm at a loss as to how to get this working. I'm hoping some of you Laravel ninjas will spot the issue, but let me know if you need to see additional information or have suggestions. Any and all help is greatly appreciated.