mirror of
https://github.com/filamentphp/filament.git
synced 2026-09-24 15:42:09 +08:00
continued roles build out
This commit is contained in:
@@ -14,30 +14,42 @@ return [
|
||||
|
||||
[
|
||||
'name' => 'view users',
|
||||
'description' => 'Allow a user to view users.',
|
||||
'guard_name' => 'web',
|
||||
'is_system' => 1,
|
||||
],
|
||||
|
||||
[
|
||||
'name' => 'edit users',
|
||||
'description' => 'Allow a user to edit users.',
|
||||
'guard_name' => 'web',
|
||||
'is_system' => 1,
|
||||
],
|
||||
|
||||
[
|
||||
'name' => 'create users',
|
||||
'description' => 'Allow a user to create users.',
|
||||
'guard_name' => 'web',
|
||||
'is_system' => 1,
|
||||
],
|
||||
|
||||
[
|
||||
'name' => 'edit user roles',
|
||||
'description' => 'Allow a user to edit user roles.',
|
||||
'guard_name' => 'web',
|
||||
'is_system' => 1,
|
||||
],
|
||||
|
||||
[
|
||||
'name' => 'view roles',
|
||||
'description' => 'Allow a user to view roles.',
|
||||
'guard_name' => 'web',
|
||||
'is_system' => 1,
|
||||
],
|
||||
|
||||
[
|
||||
'name' => 'create roles',
|
||||
'description' => 'Allow a user to create roles.',
|
||||
'guard_name' => 'web',
|
||||
'is_system' => 1,
|
||||
],
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddDescriptionToPermissionsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* The name of the table for the migration.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $tableName = 'permissions';
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table($this->tableName, function (Blueprint $table) {
|
||||
if (!Schema::hasColumn($this->tableName, 'description')) {
|
||||
$table->text('description')->nullable()->after('name');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table($this->tableName, function (Blueprint $table) {
|
||||
if (Schema::hasColumn($this->tableName, 'description')) {
|
||||
$table->dropColumn('description');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class AddDescriptionToRolesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* The name of the table for the migration.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $tableName = 'roles';
|
||||
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table($this->tableName, function (Blueprint $table) {
|
||||
if (!Schema::hasColumn($this->tableName, 'description')) {
|
||||
$table->text('description')->nullable()->after('name');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table($this->tableName, function (Blueprint $table) {
|
||||
if (Schema::hasColumn($this->tableName, 'description')) {
|
||||
$table->dropColumn('description');
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"/js/app.js": "/js/app.js?id=f4941a7bc57a4dca4d67",
|
||||
"/css/app.css": "/css/app.css?id=5c3f76d5f9f00bd976bf"
|
||||
"/css/app.css": "/css/app.css?id=ad2238a40d3fb248114a"
|
||||
}
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
<div {{ $attributes->merge(['class' => 'flex flex-col']) }}>
|
||||
<div class="-my-2 py-2 overflow-x-auto sm:-mx-6 sm:px-6 lg:-mx-8 lg:px-8">
|
||||
<div class="align-middle inline-block min-w-full shadow rounded overflow-hidden">
|
||||
<table class="min-w-full">
|
||||
<thead class="bg-gray-50 dark:bg-gray-700 text-left text-xs leading-4 text-gray-500 dark:text-gray-400 uppercase tracking-wider">
|
||||
<tr>
|
||||
@foreach($headers as $header)
|
||||
<th class="px-6 py-3 font-medium"{!! $loop->last && isset($rows[0]['row_action']) ? ' colspan="2"' : '' !!}>
|
||||
{{ $header }}
|
||||
</th>
|
||||
@endforeach
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="bg-white dark:bg-gray-800 text-gray-500 dark:text-white text-sm leading-5">
|
||||
@foreach ($rows as $row)
|
||||
<tr>
|
||||
@foreach($headers as $column => $header)
|
||||
<td class="px-6 py-4 whitespace-no-wrap border-t border-gray-200 dark:border-gray-700">
|
||||
{{ $row[$column] }}
|
||||
</td>
|
||||
@endforeach
|
||||
@isset($row['row_action'])
|
||||
<td class="px-6 py-4 whitespace-no-wrap border-t border-gray-200 dark:border-gray-700 font-medium text-right">
|
||||
<a href="{{ $row['row_action']['url'] }}" class="transition-colors duration-200 text-indigo-500 dark:text-indigo-400 hover:text-indigo-700 dark-hover:text-indigo-200">{{ $row['row_action']['label'] }}</a>
|
||||
</td>
|
||||
@endisset
|
||||
</tr>
|
||||
@endforeach
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -1,8 +1,9 @@
|
||||
@section('title', __('filament::admin.roles'))
|
||||
|
||||
<div>
|
||||
@foreach ($roles as $role)
|
||||
<div>{{ $role->name }}</div>
|
||||
@endforeach
|
||||
|
||||
<x-filament-table :headers="$headers" :rows="$rows" />
|
||||
|
||||
{{ $roles->links('filament::partials.links') }}
|
||||
|
||||
</div>
|
||||
@@ -1,7 +1,7 @@
|
||||
@section('title', __('filament::admin.users'))
|
||||
|
||||
<div>
|
||||
<ul class="mb-6 grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
<ul class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-4">
|
||||
@foreach ($users as $user)
|
||||
<li wire:key="{{ $user->id }}" class="flex">
|
||||
<a class="flex-grow p-4 bg-white dark:bg-gray-800 shadow rounded flex items-center" href="{{ route('filament.admin.users.edit', ['id' => $user->id]) }}">
|
||||
@@ -18,14 +18,18 @@
|
||||
<div class="text-xs leading-none font-mono text-gray-400">
|
||||
{{ $user->email }}
|
||||
</div>
|
||||
</div>
|
||||
@if ($user->is_super_admin)
|
||||
<div class="flex-shrink-0">
|
||||
<span class="inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium leading-4 text-gray-800 dark:text-gray-50 bg-gray-100 dark:bg-gray-500">
|
||||
{{ __('filament::permissions.super_admin') }}
|
||||
</span>
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
<div class="flex-shrink-0">
|
||||
@if ($user->is_super_admin)
|
||||
<x-filament-pill>{{ __('filament::permissions.super_admin') }}</x-filament-pill>
|
||||
@elseif (count($user->roles))
|
||||
<ul>
|
||||
@foreach($user->roles as $role)
|
||||
<li><x-filament-pill>{{ $role->name }}</x-filament-pill></li>
|
||||
@endforeach
|
||||
</ul>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</li>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
@if ($paginator->hasPages())
|
||||
<ul class="relative z-0 inline-flex shadow-sm rounded" role="navigation">
|
||||
<ul class="mt-6 relative z-0 inline-flex shadow-sm rounded" role="navigation">
|
||||
{{-- Previous Page Link --}}
|
||||
@if ($paginator->onFirstPage())
|
||||
<li class="relative inline-flex items-center px-2 py-2 rounded-l border border-gray-300 dark:border-gray-700 bg-white dark:bg-gray-800 text-sm leading-5 font-medium text-gray-400" aria-disabled="true" aria-label="@lang('pagination.previous')">
|
||||
|
||||
+2
-1
@@ -45,9 +45,10 @@ Route::name('admin.')->middleware('auth.filament')->group(function () {
|
||||
Route::livewire('/', 'filament::dashboard')->name('dashboard');
|
||||
|
||||
Route::livewire('users', 'filament::users')->name('users.index');
|
||||
Route::livewire('user/{id}', 'filament::user-edit')->name('users.edit');
|
||||
Route::livewire('users/{id}', 'filament::user-edit')->name('users.edit');
|
||||
|
||||
Route::livewire('roles', 'filament::roles')->name('roles.index');
|
||||
Route::livewire('roles/{id}', 'filament::role-edit')->name('roles.edit');
|
||||
|
||||
});
|
||||
|
||||
|
||||
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace Filament\Http\Components;
|
||||
|
||||
use Illuminate\View\Component;
|
||||
|
||||
class Pill extends Component
|
||||
{
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*
|
||||
* @return \Illuminate\View\View|string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return <<<'blade'
|
||||
<span {{ $attributes->merge(['class' => 'inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium leading-4 text-gray-800 dark:text-gray-50 bg-gray-100 dark:bg-gray-500']) }}>
|
||||
{{ $slot }}
|
||||
</span>
|
||||
blade;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
<?php
|
||||
|
||||
namespace Filament\Http\Components;
|
||||
|
||||
use Illuminate\View\Component;
|
||||
|
||||
class Table extends Component
|
||||
{
|
||||
/**
|
||||
* The table headers.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $headers;
|
||||
|
||||
/**
|
||||
* The table rows.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
public $rows;
|
||||
|
||||
/**
|
||||
* Create the component instance.
|
||||
*
|
||||
* @param array $headers
|
||||
* @param array $rows
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(array $headers, array $rows)
|
||||
{
|
||||
$this->headers = $headers;
|
||||
$this->rows = $rows;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the view / contents that represent the component.
|
||||
*
|
||||
* @return \Illuminate\View\View|string
|
||||
*/
|
||||
public function render()
|
||||
{
|
||||
return view('filament::components.table');
|
||||
}
|
||||
}
|
||||
@@ -16,8 +16,24 @@ class Roles extends Component
|
||||
$roleClass = app(RoleContract::class);
|
||||
$this->authorize('view', $roleClass);
|
||||
|
||||
$roles = $roleClass::paginate(48);
|
||||
|
||||
return view('filament::livewire.roles', [
|
||||
'roles' => $roleClass::paginate(24),
|
||||
'roles' => $roles,
|
||||
'headers' => [
|
||||
'id' => __('ID'),
|
||||
'name' => __('Name'),
|
||||
'description' => __('Description'),
|
||||
],
|
||||
'rows' => $roles->map(function ($role) {
|
||||
/*
|
||||
$role->row_action = [
|
||||
'url' => route('filament.admin.roles.edit', ['id' => $role->id]),
|
||||
'label' => __('Edit'),
|
||||
];
|
||||
*/
|
||||
return $role;
|
||||
})->values()->toArray(),
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user