How to replace space with dash in Laravel


I am developing a project in which i need to make the URLs of pages and when the user submits the title of pages and title’s space should be replaced with “-” so that it can be in correct format such as  how-to-replace-space-with-dash-in-laravel


Sometime you might need to replace some thing with any predefined things such as space “.” or any other symbol or character etc. To resolve this we need to use PHP function str_replace()

$str=Str::replace(' ','-' ,$request->title); 

Leave a Comment