@aniya.jaskolski
To create SEO-friendly URLs in Laravel, you can follow these steps:
- Make sure you have Laravel installed and set up on your system.
- Open the "routes/web.php" file in your Laravel project, where you define your routes.
- In the route definition, instead of using the default format like "/product/{id}", you can use a more descriptive and SEO-friendly format, such as "/product/{slug}".
- To generate the slug for the URL, you can use the Laravel Str::slug() helper function. This function takes a string as input and converts it into a URL-friendly format.
- In your route closure or controller method, fetch the data from the database based on the slug, rather than the ID. You can use Eloquent's "where('slug', $slug)->first()" method to fetch the data using the slug.
- Update your database schema to include a "slug" column in the table corresponding to the entity you want to create SEO-friendly URLs for. When creating or updating a record, populate the slug column with the URL-friendly version of the title or relevant information using the Str::slug() function.
- To display the SEO-friendly URL in your views or generate links to your SEO-friendly URLs, you can use the Laravel helper function url(). For example, "url('/product/'.$product->slug)".
By following these steps, you can create SEO-friendly URLs in your Laravel project, making your website more search engine friendly.