I currently have a route that needs to link to a controller. The controller needs to give back the projects.blade.php file. It gives me the homepage instead.
These are the routes I currently have
Route::get('/', [AppHttpControllersHomepageController::class, 'index'])->name('homepage');
Route::get('/projects', [AppHttpControllersHomepageController::class, 'index'])->name('projects');
This is what is in the controller currently:
class projects extends Controller
{
public function index()
{
return view('projects');
}
}
and then I have my blade file which just contains this:
@section('content')
<main>
<button href="upload.blade.php"> Make a project </button>
</main>
@endsection
I am using a template file for the rest of my html. (No, I didn’t copy and paste the main into the template file I have, I did check for that)
Any idea of why this is happening and how I can fix this? I do also have a standard laravel login which I can link to without any problems.
2
Answers
Route Names:
It’s important to ensure that your routes have distinct names. In your code, both the homepage and projects routes have the name ‘homepage’, which might be causing conflicts. Change the name of the projects route to something unique like ‘projects’:
Button Link:
The button in your blade file uses the href attribute, which is not the correct attribute for defining a link. Use the a tag for creating hyperlinks, and specify the correct URL using the href attribute:
Route and Controller Names:
Make sure your controller class is named correctly and follows Laravel’s naming conventions. It should be named ProjectsController (with a capital ‘P’) to match the Laravel convention for controllers. Also, ensure the controller is located in the correct directory:
Update your controller accordingly:
Blade File Location:
Ensure that the projects.blade.php file is located in the correct directory within the resources/views folder. It should be in a folder structure that matches your controller’s namespace. For example, if your controller is in the AppHttpControllers namespace, the blade file should be in resources/views/projects.
You have a couple of errors here.
First of all you should change your routes like this:
After that, your controller will be: