Last active
March 16, 2020 19:42
-
-
Save Tjoosten/2a30f56693c1324c5d65f21a55c54720 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Providers; | |
use App\Policies\UserPolicy; | |
use App\User; | |
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider; | |
use Illuminate\Support\Facades\Gate; | |
/** | |
* Class AuthServiceProvider | |
* | |
* @package App\Providers | |
*/ | |
class AuthServiceProvider extends ServiceProvider | |
{ | |
/** @var array $policies The policy mappings for the application. */ | |
protected $policies = [ | |
UserPolicy::class => User::class, | |
\App\Policies\SignaturePolicy::class => \App\Domain\Petition\Models\Signature::class, | |
]; | |
public function boot(): void | |
{ | |
$this->registerPolicies(); | |
// Implicitly grant "Super Admin" role all permissions | |
// This works in the app by using gate-related functions like auth()->user->can() and @can() | |
// Gate::before(function ($user, $ability) { | |
// return $user->hasRole('Super Admin') ? true : null; | |
// }); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Domain\Petition\Models; | |
use App\Domain\Petition\Models\Presenters\SetAttributePresenter; | |
use Illuminate\Database\Eloquent\Model; | |
use Illuminate\Database\Eloquent\Relations\BelongsTo; | |
/** | |
* Class Signature | |
* | |
* @package App\Domain\Petition\Models | |
*/ | |
class Signature extends Model | |
{ | |
use SetAttributePresenter; | |
/** | |
* Guarded fields for the signature table. | |
* | |
* @return array | |
*/ | |
protected $guarded = ['id']; | |
public function postal(): BelongsTo | |
{ | |
return $this->belongsTo(Postal::class); | |
} | |
public function getNameAttribute(): string | |
{ | |
return ucwords($this->voornaam . ' ' . $this->achternaam); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Policies; | |
use App\Domain\Petition\Models\Signature; | |
use App\Domain\Users\Enums\UserRoles; | |
use App\User; | |
use Illuminate\Auth\Access\HandlesAuthorization; | |
class SignaturePolicy | |
{ | |
use HandlesAuthorization; | |
public function delete(User $user, Signature $signature): bool | |
{ | |
return $user->hasRole(UserRoles::WEBMASTER); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App; | |
use App\Domain\Users\Models\Presenters\SetAttributePresenter; | |
use App\Domain\Users\Models\Presenters\GetAttributePresenter; | |
use App\Domain\Users\Models\Presenters\UrlPresenter; | |
use Illuminate\Contracts\Auth\MustVerifyEmail; | |
use Illuminate\Foundation\Auth\User as Authenticatable; | |
use Illuminate\Notifications\Notifiable; | |
use Illuminate\Support\Facades\Cache; | |
use Spatie\Permission\Traits\HasRoles; | |
use Cog\Contracts\Ban\Bannable as BannableContract; | |
use Cog\Laravel\Ban\Traits\Bannable; | |
/** | |
* Class User | |
* | |
* @package App | |
*/ | |
class User extends Authenticatable implements BannableContract | |
{ | |
use Bannable; | |
use Notifiable; | |
use HasRoles; | |
use SetAttributePresenter; | |
use GetAttributePresenter; | |
/** @var array $fillable The attributes that are mass assignable. */ | |
protected $fillable = ['firstname', 'lastname', 'email', 'password',]; | |
/** @var array $hidden The attributes that should be hidden for arrays. */ | |
protected $hidden = ['password', 'remember_token']; | |
/** @var array The attributes that should be cast to native types. */ | |
protected $casts = ['email_verified_at' => 'datetime']; | |
/** | |
* Method for leveraging a better URI strategy | |
* | |
* @see https://laravel-news.com/leverage-eloquent-to-prepare-your-urls | |
* @return UrlPresenter | |
*/ | |
public function getUrlAttribute() | |
{ | |
return new UrlPresenter($this); | |
} | |
public function isOnline(): bool | |
{ | |
return Cache::has('user-is-online-'.$this->id); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="container-fluid pb-3"> | |
<div class="card border-0 mb-0 shadow-sm card-body"> | |
<div class="table-responsive"> | |
<table class="table table-sm mb-0 table-hover"> | |
<thead> | |
<tr> | |
<th class="border-top-0" scope="col">Stad</th> | |
<th class="border-top-0" scope="col">Naam</th> | |
<th class="border-top-0" scope="col">Email adres</th> | |
<th class="border-top-0" scope="col">Getekend op</th> | |
<th class="border-top-0" scope="col"> </th> {{-- Column specified only for the functions --}} | |
</tr> | |
</thead> | |
<tbody> | |
@forelse($signatures as $signature) {{-- Loop trough the signatures --}} | |
<tr> | |
<td class="text-secondary font-weight-bolder">{{ $signature->postal->code }} {{ $signature->postal->city->first()->name }}</td> | |
<td>{{ $signature->name }}</td> | |
<td>{{ $signature->email }}</td> | |
<td> | |
{{ $signature->created_at->format('d/m/Y H:i:s') }} | |
<span class="small text-muted">({{ $signature->created_at->diffForHumans() }})</span> | |
</td> | |
<td> {{-- Options --}} | |
<span class="float-right"> | |
@can ('delete', $signature) {{-- Determine whether the user can delete the signature or not --}} | |
<a href="" class="text-danger text-decoration-none"> | |
<i class="fa fas fa-trash-alt"></i> | |
</a> | |
@endcan | |
</span> | |
</td> {{-- // Options --}} | |
</tr> | |
@empty {{-- No signatures are found in the application --}} | |
<tr> | |
<td class="text-muted" colspan="5"> | |
Er zijn momenteel geen handtekeningen gevonden in {{ config('app.name') }} | |
</td> | |
</tr> | |
@endforelse | |
</tbody> | |
</table> | |
</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment