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.