Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 35 additions & 13 deletions app/Models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,65 @@

namespace App\Models;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Orchid\Platform\Models\User as Authenticatable;

class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable;

/**
* The attributes that are mass assignable.
*
* @var array<int, string>
* @var array
*/
protected $fillable = [
'name',
'email',
'password',
'permissions',
];

/**
* The attributes that should be hidden for serialization.
* The attributes excluded from the model's JSON form.
*
* @var array<int, string>
* @var array
*/
protected $hidden = [
'password',
'remember_token',
'permissions',
];

/**
* The attributes that should be cast.
* The attributes that should be cast to native types.
*
* @var array<string, string>
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
'permissions' => 'array',
'email_verified_at' => 'datetime',
];

/**
* The attributes for which you can use filters in url.
*
* @var array
*/
protected $allowedFilters = [
'id',
'name',
'email',
'permissions',
];

/**
* The attributes for which can use sort in url.
*
* @var array
*/
protected $allowedSorts = [
'id',
'name',
'email',
'updated_at',
'created_at',
];
}
66 changes: 66 additions & 0 deletions app/Orchid/Filters/RoleFilter.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

declare(strict_types=1);

namespace App\Orchid\Filters;

use Illuminate\Database\Eloquent\Builder;
use Orchid\Filters\Filter;
use Orchid\Platform\Models\Role;
use Orchid\Screen\Field;
use Orchid\Screen\Fields\Select;

class RoleFilter extends Filter
{
/**
* @return string
*/
public function name(): string
{
return __('Roles');
}

/**
* The array of matched parameters.
*
* @return array|null
*/
public function parameters(): ?array
{
return ['role'];
}

/**
* @param Builder $builder
*
* @return Builder
*/
public function run(Builder $builder): Builder
{
return $builder->whereHas('roles', function (Builder $query) {
$query->where('slug', $this->request->get('role'));
});
}

/**
* @return Field[]
*/
public function display(): array
{
return [
Select::make('role')
->fromModel(Role::class, 'name', 'slug')
->empty()
->value($this->request->get('role'))
->title(__('Roles')),
];
}

/**
* @return string
*/
public function value(): string
{
return $this->name() . ': ' . Role::where('slug', $this->request->get('role'))->first()->name;
}
}
29 changes: 29 additions & 0 deletions app/Orchid/Layouts/Examples/ChartBarExample.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

declare(strict_types=1);

namespace App\Orchid\Layouts\Examples;

use Orchid\Screen\Layouts\Chart;

class ChartBarExample extends Chart
{
/**
* @var string
*/
protected $title = 'Bar Chart';

/**
* Available options:
* 'bar', 'line',
* 'pie', 'percentage'.
*
* @var string
*/
protected $type = 'bar';

/**
* @var string
*/
protected $target = 'charts';
}
48 changes: 48 additions & 0 deletions app/Orchid/Layouts/Examples/ChartLineExample.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php

declare(strict_types=1);

namespace App\Orchid\Layouts\Examples;

use Orchid\Screen\Layouts\Chart;

class ChartLineExample extends Chart
{
/**
* @var string
*/
protected $title = 'Line Chart';

/**
* @var string
*/
protected $target = 'charts';

/**
* Configuring line.
*
* @var array
*/
protected $lineOptions = [
'spline' => 1,
'regionFill' => 1,
'hideDots' => 0,
'hideLine' => 0,
'heatline' => 0,
'dotSize' => 3,
];

/**
* To highlight certain values on the Y axis, markers can be set.
* They will shown as dashed lines on the graph.
*/
protected function markers(): ?array
{
return [
[
'label' => 'Medium',
'value' => 40,
],
];
}
}
34 changes: 34 additions & 0 deletions app/Orchid/Layouts/Examples/ChartPercentageExample.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace App\Orchid\Layouts\Examples;

use Orchid\Screen\Layouts\Chart;

class ChartPercentageExample extends Chart
{
/**
* @var string
*/
protected $title = 'Percentage Chart';

/**
* @var int
*/
protected $height = 160;

/**
* Available options:
* 'bar', 'line',
* 'pie', 'percentage'.
*
* @var string
*/
protected $type = 'percentage';

/**
* @var string
*/
protected $target = 'charts';
}
34 changes: 34 additions & 0 deletions app/Orchid/Layouts/Examples/ChartPieExample.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

declare(strict_types=1);

namespace App\Orchid\Layouts\Examples;

use Orchid\Screen\Layouts\Chart;

class ChartPieExample extends Chart
{
/**
* @var string
*/
protected $title = 'Pie Chart';

/**
* @var int
*/
protected $height = 350;

/**
* Available options:
* 'bar', 'line',
* 'pie', 'percentage'.
*
* @var string
*/
protected $type = 'pie';

/**
* @var string
*/
protected $target = 'charts';
}
38 changes: 38 additions & 0 deletions app/Orchid/Layouts/Role/RoleEditLayout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

namespace App\Orchid\Layouts\Role;

use Orchid\Screen\Field;
use Orchid\Screen\Fields\Input;
use Orchid\Screen\Layouts\Rows;

class RoleEditLayout extends Rows
{
/**
* Views.
*
* @return Field[]
*/
public function fields(): array
{
return [
Input::make('role.name')
->type('text')
->max(255)
->required()
->title(__('Name'))
->placeholder(__('Name'))
->help(__('Role display name')),

Input::make('role.slug')
->type('text')
->max(255)
->required()
->title(__('Slug'))
->placeholder(__('Slug'))
->help(__('Actual name in the system')),
];
}
}
47 changes: 47 additions & 0 deletions app/Orchid/Layouts/Role/RoleListLayout.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

declare(strict_types=1);

namespace App\Orchid\Layouts\Role;

use Orchid\Platform\Models\Role;
use Orchid\Screen\Actions\Link;
use Orchid\Screen\Fields\Input;
use Orchid\Screen\Layouts\Table;
use Orchid\Screen\TD;

class RoleListLayout extends Table
{
/**
* @var string
*/
public $target = 'roles';

/**
* @return TD[]
*/
public function columns(): array
{
return [
TD::make('name', __('Name'))
->sort()
->cantHide()
->filter(Input::make())
->render(function (Role $role) {
return Link::make($role->name)
->route('platform.systems.roles.edit', $role->id);
}),

TD::make('slug', __('Slug'))
->sort()
->cantHide()
->filter(Input::make()),

TD::make('created_at', __('Created'))
->sort()
->render(function (Role $role) {
return $role->created_at->toDateTimeString();
}),
];
}
}
Loading