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
Post a Comment