13 changed files with 362 additions and 74 deletions
-
36app/Entities/Users/Role.php
-
101app/Entities/Users/User.php
-
21app/Entities/Users/UserRole.php
-
35app/Http/Controllers/Users/UsersController.php
-
37database/migrations/2017_10_28_170121_create_agencies_table.php
-
33database/migrations/2017_11_14_061927_create_user_roles_table.php
-
26resources/lang/id/user.php
-
6resources/views/users/create.blade.php
-
6resources/views/users/edit.blade.php
-
2resources/views/users/index.blade.php
-
1resources/views/users/show.blade.php
-
58tests/Feature/Users/ManageUsersTest.php
-
74tests/Unit/Models/UserTest.php
@ -0,0 +1,36 @@ |
|||
<?php |
|||
|
|||
namespace App\Entities\Users; |
|||
|
|||
use App\Entities\ReferenceAbstract; |
|||
|
|||
/** |
|||
* Role Class |
|||
*/ |
|||
class Role extends ReferenceAbstract |
|||
{ |
|||
protected static $lists = [ |
|||
1 => 'admin', |
|||
2 => 'worker', |
|||
]; |
|||
|
|||
public static function getNameById($roleId) |
|||
{ |
|||
return trans('user.roles.'.static::$lists[$roleId]); |
|||
} |
|||
|
|||
public static function getIdByName($roleName) |
|||
{ |
|||
return array_search($roleName, static::$lists); |
|||
} |
|||
|
|||
public static function toArray() |
|||
{ |
|||
$lists = []; |
|||
foreach (static::$lists as $key => $value) { |
|||
$lists[$key] = trans('user.roles.'.$value); |
|||
} |
|||
|
|||
return $lists; |
|||
} |
|||
} |
|||
@ -0,0 +1,21 @@ |
|||
<?php |
|||
|
|||
namespace App\Entities\Users; |
|||
|
|||
use Illuminate\Database\Eloquent\Model; |
|||
|
|||
/** |
|||
* @author Nafies Luthfi <nafiesL@gmail.com> |
|||
*/ |
|||
class UserRole extends Model |
|||
{ |
|||
protected $table = 'user_roles'; |
|||
public $timestamps = false; |
|||
protected $appends = ['name']; |
|||
protected $fillable = ['user_id', 'role_id']; |
|||
|
|||
public function getNameAttribute() |
|||
{ |
|||
return Role::getNameById($this->role_id); |
|||
} |
|||
} |
|||
@ -1,37 +0,0 @@ |
|||
<?php |
|||
|
|||
use Illuminate\Database\Migrations\Migration; |
|||
use Illuminate\Database\Schema\Blueprint; |
|||
use Illuminate\Support\Facades\Schema; |
|||
|
|||
class CreateAgenciesTable extends Migration |
|||
{ |
|||
/** |
|||
* Run the migrations. |
|||
* |
|||
* @return void |
|||
*/ |
|||
public function up() |
|||
{ |
|||
Schema::create('agencies', function (Blueprint $table) { |
|||
$table->increments('id'); |
|||
$table->string('name'); |
|||
$table->string('email')->unique(); |
|||
$table->string('address')->nullable(); |
|||
$table->string('phone')->nullable(); |
|||
$table->string('website')->nullable(); |
|||
$table->unsignedInteger('owner_id'); |
|||
$table->timestamps(); |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* Reverse the migrations. |
|||
* |
|||
* @return void |
|||
*/ |
|||
public function down() |
|||
{ |
|||
Schema::dropIfExists('agencies'); |
|||
} |
|||
} |
|||
@ -0,0 +1,33 @@ |
|||
<?php |
|||
|
|||
use Illuminate\Database\Migrations\Migration; |
|||
use Illuminate\Database\Schema\Blueprint; |
|||
use Illuminate\Support\Facades\Schema; |
|||
|
|||
class CreateUserRolesTable extends Migration |
|||
{ |
|||
/** |
|||
* Run the migrations. |
|||
* |
|||
* @return void |
|||
*/ |
|||
public function up() |
|||
{ |
|||
Schema::create('user_roles', function (Blueprint $table) { |
|||
$table->unsignedInteger('user_id'); |
|||
$table->unsignedTinyInteger('role_id'); |
|||
|
|||
$table->unique(['user_id', 'role_id'], 'user_role_unique'); |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* Reverse the migrations. |
|||
* |
|||
* @return void |
|||
*/ |
|||
public function down() |
|||
{ |
|||
Schema::dropIfExists('user_roles'); |
|||
} |
|||
} |
|||
Write
Preview
Loading…
Cancel
Save
Reference in new issue