php - Return data with no whitespace -


i using laravel 5.2. looking querying usernames eloquent in order create unique profile page. issue having usernames returning white space e.g. john doe need return no white space johndoe or johndoe. thanks.

public function show($username) {     try     {         $user = str_replace(' ', '', user::wherename($username)->firstorfail());         dd($user);      }     catch(modelnotfoundexception $e)     {         return redirect()->action('homecontroller@index');     } } 

you can create function on user model returns name without spaces. so:

public function getnamewithoutspaces() {     return preg_replace('/\s+/', '', $this->name); } 

this way can name without spaces wherever needed without having use str_replace function time.


Comments

Popular posts from this blog

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -