fatema's avatar

Link to PHP page

I'm trying to link a page to my homepage but I keep this error:

ErrorException in UrlGenerator.php line 304:
Route [course] not defined. (View: C:\xampp\htdocs\blog\resources\views\course.blade.php)

I'm using this code to link:

<a href="{{ url('/course') }}">Add Course</a><br>

And I'm using this code for routing:

Route::get('course', function () {
    return view('course');
});

How can I resolve this issue?

0 likes
3 replies
shakti's avatar

please add / in route it might help

Route::get('/course',function(){
});
jimmy0699's avatar

there is no need to use / in url() helper function

AddWebContribution's avatar

I think you should try below code

Your Route file

Route::get('course', function () {
    return view('course')->name('course');
});

Your Code link

<a href="{{ route('course') }}">Add Course</a><br>

OR you can add direct url

<a href="{{ url('course') }}">Add Course</a><br>

Hope, it's work for you !

Please or to participate in this conversation.