diff --git a/app/Entities/Projects/Project.php b/app/Entities/Projects/Project.php index 7e63c5c..a927ea8 100755 --- a/app/Entities/Projects/Project.php +++ b/app/Entities/Projects/Project.php @@ -19,6 +19,11 @@ class Project extends Model { protected $guarded = ['id','created_at','updated_at']; // protected $dates = ['start_date','end_date']; + public function nameLink() + { + return link_to_route('projects.show', $this->name, [$this->id], ['target' => '_blank']); + } + public function features() { return $this->hasMany(Feature::class)->orderBy('position'); diff --git a/app/Entities/Users/HasRoles.php b/app/Entities/Users/HasRoles.php deleted file mode 100644 index 188ecdf..0000000 --- a/app/Entities/Users/HasRoles.php +++ /dev/null @@ -1,59 +0,0 @@ -belongsToMany(Role::class); - } - - /** - * Assign the given role to the user. - * - * @param string $role - * @return mixed - */ - public function assignRole($role) - { - return $this->roles()->save( - Role::whereName($role)->firstOrFail() - ); - } - - /** - * Determine if the user has the given role. - * - * @param mixed $role - * @return boolean - */ - public function hasRole($role) - { - if (is_string($role)) { - return $this->roles->contains('name', $role); - } - - return !! $role->intersect($this->roles)->count(); - } - - public function hasRoles(array $roleNameArray) - { - return $this->roles->contains(function($role, $key) use ($roleNameArray) { - return in_array($role->name, $roleNameArray); - }); - } - - public function scopeHasRoles($query, array $roleNameArray) - { - return $query->whereHas('roles', function($q) use ($roleNameArray) { - $q->whereIn('name',$roleNameArray); - }); - } -} diff --git a/app/Entities/Users/User.php b/app/Entities/Users/User.php index d5953ee..9ae7161 100644 --- a/app/Entities/Users/User.php +++ b/app/Entities/Users/User.php @@ -9,7 +9,7 @@ use Laracasts\Presenter\PresentableTrait; class User extends Authenticatable { - use Notifiable, PresentableTrait, HasRoles; + use Notifiable, PresentableTrait; protected $fillable = ['name', 'email', 'password']; protected $hidden = ['password', 'remember_token', 'api_token']; @@ -19,4 +19,61 @@ class User extends Authenticatable { $this->attributes['password'] = bcrypt($value); } + + public function nameLink() + { + return link_to_route('users.show', $this->name, [$this->id], ['target' => '_blank']); + } + + /** + * A user may have multiple roles. + * + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany + */ + public function roles() + { + return $this->belongsToMany(Role::class); + } + + /** + * Assign the given role to the user. + * + * @param string $role + * @return mixed + */ + public function assignRole($role) + { + return $this->roles()->save( + Role::whereName($role)->firstOrFail() + ); + } + + /** + * Determine if the user has the given role. + * + * @param mixed $role + * @return boolean + */ + public function hasRole($role) + { + if (is_string($role)) { + return $this->roles->contains('name', $role); + } + + return !! $role->intersect($this->roles)->count(); + } + + public function hasRoles(array $roleNameArray) + { + return $this->roles->contains(function($role, $key) use ($roleNameArray) { + return in_array($role->name, $roleNameArray); + }); + } + + public function scopeHasRoles($query, array $roleNameArray) + { + return $query->whereHas('roles', function($q) use ($roleNameArray) { + $q->whereIn('name',$roleNameArray); + }); + } } diff --git a/resources/views/projects/index.blade.php b/resources/views/projects/index.blade.php index 7e75d88..544c14f 100755 --- a/resources/views/projects/index.blade.php +++ b/resources/views/projects/index.blade.php @@ -11,7 +11,7 @@ {!! Form::open(['method'=>'get','class'=>'form-inline']) !!} {!! FormField::select('status', getProjectStatusesList(), ['value' => Request::get('status'), 'placeholder'=> 'Semua Project']) !!} - {!! Form::text('q', Request::get('q'), ['class'=>'form-control index-search-field','placeholder'=>trans('project.search'),'style' => 'width:350px']) !!} + {!! Form::text('q', Request::get('q'), ['class'=>'form-control index-search-field','placeholder'=>trans('project.search'),'style' => 'width:100%;max-width:350px']) !!} {!! Form::submit(trans('project.search'), ['class' => 'btn btn-info btn-sm']) !!} {!! link_to_route('projects.index','Reset',[],['class' => 'btn btn-default btn-sm']) !!} {!! Form::close() !!} @@ -33,7 +33,7 @@ @forelse($projects as $key => $project) {{ $projects->firstItem() + $key }} - {{ $project->name }} + {{ $project->nameLink() }} {{ $project->start_date }} {{ $project->present()->workDuration }} {{-- {{ $project->payments_count }} --}} diff --git a/tests/Unit/Models/ProjectTest.php b/tests/Unit/Models/ProjectTest.php index 9a7c7a3..06f2141 100644 --- a/tests/Unit/Models/ProjectTest.php +++ b/tests/Unit/Models/ProjectTest.php @@ -131,4 +131,13 @@ class ProjectTest extends TestCase $project = factory(Project::class)->create(); $this->assertTrue($project->files instanceof Collection); } + + /** @test */ + public function it_has_name_link_method() + { + $project = factory(Project::class)->make(); + $this->assertEquals(link_to_route('projects.show', $project->name, [$project->id], [ + 'target' => '_blank' + ]), $project->nameLink()); + } } diff --git a/tests/Unit/Models/UserTest.php b/tests/Unit/Models/UserTest.php new file mode 100644 index 0000000..88752b3 --- /dev/null +++ b/tests/Unit/Models/UserTest.php @@ -0,0 +1,19 @@ +create(); + + $this->assertEquals(link_to_route('users.show', $user->name, [$user->id], [ + 'target' => '_blank' + ]), $user->nameLink()); + } +}