How to generate and display URLs and links using Blade in Laravel?

To generate and display URLs and links using Blade in Laravel, you can use the url() helper function and the @ symbol in Blade directives. Here are some examples:

  1. To generate a basic URL:
<a href="{{ url('path/to/page') }}">Link</a>
  1. To generate a URL with route parameters:
<a href="{{ url('users', ['id' => 1]) }}">User Profile</a>

This will generate a URL like /users?id=1.

  1. To generate a URL using named routes:
<a href="{{ route('route.name') }}">Named Route</a>

Make sure to define the named route in your web.php routes file using the name() method.

  1. To generate a URL with query parameters:
<a href="{{ url('path/to/page', ['param1' => 'value1', 'param2' => 'value2']) }}">Link</a>

This will generate a URL like /path/to/page?param1=value1&param2=value2.

  1. To generate a URL with an anchor tag:
<a href="{{ url('path/to/page') }}#section">Link with Anchor</a>

This will generate a URL like /path/to/page#section.

Note: Remember to use the {!! !!} directive to render the link as HTML in Blade templates to prevent HTML encoding.

These are some of the ways you can generate and display URLs and links using Blade in Laravel.