parent
4ca6f00c1b
commit
99a92c6106
@ -106,6 +106,10 @@ class EjaculationController extends Controller
|
||||
{
|
||||
$ejaculation = Ejaculation::findOrFail($id);
|
||||
|
||||
if (Auth::user()->cant('edit', $ejaculation)) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
return view('ejaculation.edit')->with(compact('ejaculation'));
|
||||
}
|
||||
|
||||
@ -113,6 +117,10 @@ class EjaculationController extends Controller
|
||||
{
|
||||
$ejaculation = Ejaculation::findOrFail($id);
|
||||
|
||||
if (Auth::user()->cant('edit', $ejaculation)) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$inputs = $request->all();
|
||||
|
||||
$validator = Validator::make($inputs, [
|
||||
@ -163,6 +171,11 @@ class EjaculationController extends Controller
|
||||
public function destroy($id)
|
||||
{
|
||||
$ejaculation = Ejaculation::findOrFail($id);
|
||||
|
||||
if (Auth::user()->cant('edit', $ejaculation)) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
$user = User::findOrFail($ejaculation->user_id);
|
||||
$ejaculation->tags()->detach();
|
||||
$ejaculation->delete();
|
||||
|
27
app/Policies/EjaculationPolicy.php
Normal file
27
app/Policies/EjaculationPolicy.php
Normal file
@ -0,0 +1,27 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Ejaculation;
|
||||
use App\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
|
||||
class EjaculationPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Create a new policy instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
public function edit(User $user, Ejaculation $ejaculation): bool
|
||||
{
|
||||
return $user->id === $ejaculation->user_id;
|
||||
}
|
||||
}
|
@ -2,6 +2,8 @@
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Ejaculation;
|
||||
use App\Policies\EjaculationPolicy;
|
||||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
||||
use Illuminate\Support\Facades\Gate;
|
||||
|
||||
@ -14,6 +16,7 @@ class AuthServiceProvider extends ServiceProvider
|
||||
*/
|
||||
protected $policies = [
|
||||
'App\Model' => 'App\Policies\ModelPolicy',
|
||||
Ejaculation::class => EjaculationPolicy::class,
|
||||
];
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user