Skip to content

Commit

Permalink
Merge pull request #11 from ARCANEDEV/patch-slugs
Browse files Browse the repository at this point in the history
Updating username by using slug with dots
  • Loading branch information
arcanedev-maroc committed Sep 18, 2016
2 parents 62e5351 + d39a6f8 commit 00820b9
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 5 deletions.
20 changes: 18 additions & 2 deletions src/Models/User.php
Expand Up @@ -13,6 +13,7 @@
use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\Access\Authorizable;
use Illuminate\Support\Str;

/**
* Class User
Expand Down Expand Up @@ -134,7 +135,22 @@ public function scopeUnconfirmed($query, $code)
| ------------------------------------------------------------------------------------------------
*/
/**
* Get the full name attribute.
* Set the `username` attribute.
*
* @param string $username
*/
public function setUsernameAttribute($username)
{
$username = Str::slug(
trim($username),
config('laravel-auth.slug-separator', '.')
);

$this->attributes['username'] = $username;
}

/**
* Get the `full_name` attribute.
*
* @return string
*/
Expand All @@ -144,7 +160,7 @@ public function getFullNameAttribute()
}

/**
* Set the password attribute.
* Set the `password` attribute.
*
* @param string $password
*/
Expand Down
4 changes: 3 additions & 1 deletion src/Traits/Slugable.php
@@ -1,5 +1,7 @@
<?php namespace Arcanedev\LaravelAuth\Traits;

use Illuminate\Support\Str;

/**
* Trait Slugable
*
Expand All @@ -23,7 +25,7 @@ trait Slugable
*/
protected function slugify($value)
{
return str_slug($value, config('laravel-auth.slug-separator', '.'));
return Str::slug($value, config('laravel-auth.slug-separator', '.'));
}

/* ------------------------------------------------------------------------------------------------
Expand Down
4 changes: 2 additions & 2 deletions tests/Models/UserTest.php
Expand Up @@ -98,7 +98,7 @@ public function it_can_create()
public function it_can_activate_and_deactivate()
{
$attributes = [
'username' => 'john-doe',
'username' => 'john.doe',
'first_name' => 'John',
'last_name' => 'DOE',
'email' => 'j.doe@gmail.com',
Expand Down Expand Up @@ -514,7 +514,7 @@ private function createUser(array $attributes = [])
private function getUserAttributes()
{
return [
'username' => 'john-doe',
'username' => 'john.doe',
'first_name' => 'John',
'last_name' => 'DOE',
'email' => 'j.doe@gmail.com',
Expand Down

0 comments on commit 00820b9

Please sign in to comment.