Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

alkrauss48/simple-slides

98 stars
3 code files
View alkrauss48/simple-slides on GitHub

app/Policies/PresentationPolicy.php

Open in GitHub
use App\Models\Presentation;
use App\Models\User;
 
class PresentationPolicy
{
// ...
 
public function view(User $user, Presentation $presentation): bool
{
return $presentation->user_id === $user->id;
}
 
// ...
}

app/Http/Controllers/PresentationController.php

Open in GitHub
use App\Models\User;
use Inertia\Inertia;
use Inertia\Response;
 
class PresentationController extends Controller
{
public function show(User $user, string $slug): Response
{
$presentation = $user
->presentations()
->where('slug', $slug)
->firstOrFail();
 
if (! $presentation->canBeViewed) {
abort(403);
}
 
// ...
}
}

app/Models/Presentation.php

Open in GitHub
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Casts\Attribute;
use Illuminate\Database\Eloquent\Model;
 
class Presentation extends Model implements HasMedia
{
// ...
 
protected function canBeViewed(): Attribute
{
return Attribute::make(
get: function (mixed $value, array $attributes): bool {
if ($this->is_published) {
return true;
}
 
if (! auth()->check()) {
return false;
}
 
return auth()->user()->can('view', $this);
},
);
}
 
// ...
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.