Reputation: 45
I am have problems with routing in Laravel 8 This is my web.php file
use App\Http\Controllers\AlbumsController;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
//Route::get('/', function () {
// return view('welcome');
//});
Route::get('/', [AlbumsController::class,'index']);
This works, however, the index.blade.php file is in resources/views/albums/. If I do:
Route::get('/albums', [AlbumsController::class,'index']);
I get a Object not found error.
My Controller is
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class AlbumsController extends Controller
{
public function index(){
return view('albums.index');
}
{
At the moment there is nothing in the index.blade.php file except the word Index, I am checking if the routes work.
Your help is appreciated
Upvotes: 0
Views: 79
Reputation: 45
I have found the solution to the above question. What I did was changed: These routes from
Route::get('/albums/create', ('AlbumsController@create')
Route::get('/albums/index', ('AlbumsController@index')
to
Route::get('/', ('AlbumsController@create')
Strange as this is, it works!
Upvotes: 1
Reputation: 121
Maybe it’s because You didn’t close properly the curly brackets of your AlbumsController class. Try this instead :
class AlbumsController extends Controller
{
public function index(){
return view('albums.index');
}
}
Upvotes: 0