1

I have a Laravel 5 project that filters products by category names and displays them. Some category names contain slashes(/) and dots(.), but when I use rawurlencode() to encode the names that I retrieved from the database in order to generate urls, slashes and dots are not encoded by rawurlencode(), which leads to 404 and internal errors when I try to click those generated links.

Code in my view:

@foreach($info['categories'] as $cat)
  <a href="{{ route('listByCategory', rawurldecode($cat->description)) }}" class="list-group-item sidebar-menuitem">{{ $cat->description }}</a>
@endforeach

Here my routes file:

Route::get('/cat/{cat}', ['as' => 'listByCategory', 'uses' => 'ProductsController@display']);

And here's my controller:

class ProductsController extends Controller
{
  public function display($category)
  {
    $info = [];
    $info['title'] = $category;
    $info['products'] = DB::select('....);
    return view('myview);
  }
}

My question is: Why is rawurlencode() not encoding slashes and dots? What would be the correct approach to accomplish this?

Thanks.

Anderson Madeira
  • 420
  • 9
  • 29
  • 1
    you are using `rawurldecode` in `a` tag. aren't you suppose to use `rawurlencode`? – pinkal vansia Jul 08 '15 at 13:54
  • Sorry for that, I was really using `rawurldecode` instead of `rawurlencode`. duh! ... This is the resulting url: `http://localhost:8888/cat/CLOTHES%20%2FP.%20SHOES` but it is not encoding dots(.) and it gives me a `404` error. Even though the url did not contain the dot(.) I also get a error as if Laravel was trying to access `localhost:8888/cat/CLOTHES/PSHOES`. I cant use slashes(/) or dots(.) as part of urls? – Anderson Madeira Jul 08 '15 at 14:18
  • Possible duplicate of [How to define a Laravel route with a parameter that contains a slash character](https://stackoverflow.com/questions/21552604/how-to-define-a-laravel-route-with-a-parameter-that-contains-a-slash-character) – Andrew Mar 15 '18 at 23:20

0 Answers0