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

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -