Using URL with a slash in its value?

Posted 2 years ago by Axeia

Hello, as my site is starting to shape up more and more and more data is input I've ran into a problem. I'm using the name of an item in my database as part of the URL as it's the primary key, however this name may contain a slash which throws laravel off-track as it treats it as an URL-separator. It's quite confusing to explain so I'll show some code instead. In my view I do the following:

<th><a href="{{ url('/plushies', $plushy->name ) }}" title="added by {{ $plushy->addedBy }}">{{ $plushy->name }}</a></th>

The $plushy->name contains a slash, in this case the value is 'Matsuri/Festival Alpacasso'. Is it possible to circumvent this somehow by being creative with the routing for example? At the moment my route is simply

Route::resource('plushies', 'PlushiesController');

If not, what's the simplest way to prevent the issue altogether by replacing the / with for example '%2F' or even '|' ? Perhaps a setter can be defined on the request class to achieve this?

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.