Skip to content

Commit

Permalink
authorize events secction
Browse files Browse the repository at this point in the history
  • Loading branch information
IsharaEkanayaka committed Jul 15, 2024
1 parent 63bc7ab commit a02676a
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 9 deletions.
10 changes: 8 additions & 2 deletions app/Http/Livewire/Backend/EventsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace App\Http\Livewire\Backend;

use Illuminate\Support\Facades\Gate;
use App\Domains\Event\Models\Event;
use Illuminate\Database\Eloquent\Builder;
use Rappasoft\LaravelLivewireTables\DataTableComponent;
Expand All @@ -17,7 +18,7 @@ class EventsTable extends DataTableComponent

public function columns(): array
{
return [
$columns = [
Column::make("Title", "title")
->sortable()
->searchable(),
Expand All @@ -39,8 +40,13 @@ public function columns(): array
->sortable(),
Column::make("Updated At", "updated_at")
->sortable(),
Column::make("Actions")
];

if (Gate::allows('edit-or-delete-news')) {
$columns[] = Column::make("Actions");
}

return $columns;
}

public function query(): Builder
Expand Down
4 changes: 2 additions & 2 deletions app/Providers/AuthServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ public function boot()
// });

Gate::define('edit-or-delete-news', function ($user) {
// Logic to determine if the user can edit news
// Logic to determine if the user can edit or delete news
return $user->hasAnyPermission(['admin.access.news.edit','admin.access.news.delete']);
});

Gate::define('edit-or-delete-events', function ($user) {
// Logic to determine if the user can edit news
// Logic to determine if the user can edit or delete events
return $user->hasAnyPermission(['admin.access.events.edit','admin.access.events.delete']);
});
}
Expand Down
7 changes: 4 additions & 3 deletions resources/views/backend/event/index-table-row.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,6 @@
@endif
</x-livewire-tables::table.cell>




<x-livewire-tables::table.cell>
<div class="custom-width-1" style="width: 75px;">
{{ $row->start_at }}
Expand Down Expand Up @@ -74,12 +71,16 @@
<x-livewire-tables::table.cell>
<div class="d-flex px-0 mt-0 mb-0">
<div class="btn-group" role="group" aria-label="">
@if ($logged_in_user->hasPermissionTo('admin.access.events.edit'))
<a href="{{ route('dashboard.event.edit', $row) }}" class="btn btn-info btn-xs"><i class="fa fa-pencil"
title="Edit"></i>
</a>
@endif
@if ($logged_in_user->hasPermissionTo('admin.access.events.edit'))
<a href="{{ route('dashboard.event.delete', $row) }}" class="btn btn-danger btn-xs"><i
class="fa fa-trash" title="Delete"></i>
</a>
@endif
</div>
</div>
</x-livewire-tables::table.cell>
12 changes: 10 additions & 2 deletions routes/backend/event.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,21 @@
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Backend\EventController;

Route::group(['middleware' => ['permission:admin.access.events.edit']], function () {
Route::group(['middleware' => ['permission:admin.access.events.show|admin.access.events.create|admin.access.events.edit|admin.access.events.delete']], function () {

Route::get('/event', function () {
return view('backend.event.index');
})->name('event.index')
})
->middleware('permission:admin.access.events.show')
->name('event.index')
->breadcrumbs(function (Trail $trail) {
$trail->push(__('Home'), route('dashboard.home'))
->push(__('event'), route('dashboard.event.index'));
});

// Create
Route::get('event/create', [EventController::class, 'create'])
->middleware('permission:admin.access.events.create')
->name('event.create')
->breadcrumbs(function (Trail $trail) {
$trail->push(__('Home'), route('dashboard.home'))
Expand All @@ -25,10 +28,12 @@

// Store
Route::post('event/', [EventController::class, 'store'])
->middleware('permission:admin.access.events.create')
->name('event.store');

// Edit
Route::get('event/edit/{event}', [EventController::class, 'edit'])
->middleware('permission:admin.access.events.edit')
->name('event.edit')
->breadcrumbs(function (Trail $trail) {
$trail->push(__('Home'), route('dashboard.home'))
Expand All @@ -39,10 +44,12 @@

// Update
Route::put('event/{event}', [EventController::class, 'update'])
->middleware('permission:admin.access.events.edit')
->name('event.update');

// Delete
Route::get('event/delete/{event}', [EventController::class, 'delete'])
->middleware('permission:admin.access.events.delete')
->name('event.delete')
->breadcrumbs(function (Trail $trail) {
$trail->push(__('Home'), route('dashboard.home'))
Expand All @@ -52,5 +59,6 @@

// Destroy
Route::delete('event/{event}', [EventController::class, 'destroy'])
->middleware('permission:admin.access.events.delete')
->name('event.destroy');
});

0 comments on commit a02676a

Please sign in to comment.