wip
This commit is contained in:
27
app/Models/Concerns/HasEcommerceChannels.php
Normal file
27
app/Models/Concerns/HasEcommerceChannels.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Concerns;
|
||||
|
||||
use App\Models\Ecommerce\Channel\Channel;
|
||||
use Illuminate\Database\Eloquent\Relations\MorphMany;
|
||||
|
||||
trait HasEcommerceChannels
|
||||
{
|
||||
/**
|
||||
* User ecommerce channels
|
||||
*/
|
||||
public function channels(): MorphMany
|
||||
{
|
||||
return $this->morphMany(Channel::class, 'channelables');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the user's most recent image.
|
||||
*/
|
||||
public function channel(): ?Channel
|
||||
{
|
||||
return $this->relationLoaded('channels')
|
||||
? $this->channels->first()
|
||||
: $this->channels()->first();
|
||||
}
|
||||
}
|
||||
25
app/Models/Concerns/HasSchemalessAttributes.php
Normal file
25
app/Models/Concerns/HasSchemalessAttributes.php
Normal file
@@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Concerns;
|
||||
|
||||
use Illuminate\Database\Eloquent\Builder;
|
||||
use Spatie\SchemalessAttributes\Casts\SchemalessAttributes;
|
||||
|
||||
trait HasSchemalessAttributes
|
||||
{
|
||||
/**
|
||||
* Add Schemaless Attributes to casts
|
||||
*/
|
||||
public function initializeHasSchemalessAttributes(): void
|
||||
{
|
||||
$this->casts['options'] = SchemalessAttributes::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope for Extra attributes
|
||||
*/
|
||||
public function scopeWithExtraAttributes(): Builder
|
||||
{
|
||||
return $this->options->modelScope();
|
||||
}
|
||||
}
|
||||
26
app/Models/Concerns/InteractsWithNova.php
Normal file
26
app/Models/Concerns/InteractsWithNova.php
Normal file
@@ -0,0 +1,26 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Concerns;
|
||||
|
||||
trait InteractsWithNova
|
||||
{
|
||||
/**
|
||||
* Check if user can access nova
|
||||
*/
|
||||
public function canAccessNova(): bool
|
||||
{
|
||||
if ($this->isMe()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->hasRole(['admin', 'manager'])) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if ($this->hasRole('vendor') && $this->channel()->id) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
52
app/Models/Concerns/InteractsWithRoles.php
Normal file
52
app/Models/Concerns/InteractsWithRoles.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Concerns;
|
||||
|
||||
trait InteractsWithRoles
|
||||
{
|
||||
/**
|
||||
* Check if user is Me :)
|
||||
*/
|
||||
public function isMe(): bool
|
||||
{
|
||||
return in_array($this->email, [
|
||||
'nurmuhammet@mail.com',
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user is admin
|
||||
*/
|
||||
public function isAdmin(): bool
|
||||
{
|
||||
if ($this->isMe()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->hasRole('admin');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user is manager
|
||||
*/
|
||||
public function isManager(): bool
|
||||
{
|
||||
return $this->hasRole('manager');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user is entrepreneur
|
||||
*/
|
||||
public function isEntrepreneur(): bool
|
||||
{
|
||||
return $this->hasRole('vendor');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if user is vendor
|
||||
*/
|
||||
public function isVendor(): bool
|
||||
{
|
||||
return $this->hasRole('vendor');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user