チェックインの編集は本人のみ可能
This commit is contained in:
parent
e6657a0756
commit
bcb5abb161
@ -106,6 +106,10 @@ class EjaculationController extends Controller
|
|||||||
{
|
{
|
||||||
$ejaculation = Ejaculation::findOrFail($id);
|
$ejaculation = Ejaculation::findOrFail($id);
|
||||||
|
|
||||||
|
if (Auth::user()->cant('edit', $ejaculation)) {
|
||||||
|
abort(403);
|
||||||
|
}
|
||||||
|
|
||||||
return view('ejaculation.edit')->with(compact('ejaculation'));
|
return view('ejaculation.edit')->with(compact('ejaculation'));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,6 +117,10 @@ class EjaculationController extends Controller
|
|||||||
{
|
{
|
||||||
$ejaculation = Ejaculation::findOrFail($id);
|
$ejaculation = Ejaculation::findOrFail($id);
|
||||||
|
|
||||||
|
if (Auth::user()->cant('edit', $ejaculation)) {
|
||||||
|
abort(403);
|
||||||
|
}
|
||||||
|
|
||||||
$inputs = $request->all();
|
$inputs = $request->all();
|
||||||
|
|
||||||
$validator = Validator::make($inputs, [
|
$validator = Validator::make($inputs, [
|
||||||
@ -163,6 +171,11 @@ class EjaculationController extends Controller
|
|||||||
public function destroy($id)
|
public function destroy($id)
|
||||||
{
|
{
|
||||||
$ejaculation = Ejaculation::findOrFail($id);
|
$ejaculation = Ejaculation::findOrFail($id);
|
||||||
|
|
||||||
|
if (Auth::user()->cant('edit', $ejaculation)) {
|
||||||
|
abort(403);
|
||||||
|
}
|
||||||
|
|
||||||
$user = User::findOrFail($ejaculation->user_id);
|
$user = User::findOrFail($ejaculation->user_id);
|
||||||
$ejaculation->tags()->detach();
|
$ejaculation->tags()->detach();
|
||||||
$ejaculation->delete();
|
$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;
|
namespace App\Providers;
|
||||||
|
|
||||||
|
use App\Ejaculation;
|
||||||
|
use App\Policies\EjaculationPolicy;
|
||||||
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
|
||||||
use Illuminate\Support\Facades\Gate;
|
use Illuminate\Support\Facades\Gate;
|
||||||
|
|
||||||
@ -14,6 +16,7 @@ class AuthServiceProvider extends ServiceProvider
|
|||||||
*/
|
*/
|
||||||
protected $policies = [
|
protected $policies = [
|
||||||
'App\Model' => 'App\Policies\ModelPolicy',
|
'App\Model' => 'App\Policies\ModelPolicy',
|
||||||
|
Ejaculation::class => EjaculationPolicy::class,
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user