finish basic crud api
This commit is contained in:
@@ -19,16 +19,6 @@ class EventController extends Controller
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
@@ -60,27 +50,22 @@ class EventController extends Controller
|
||||
->setStatusCode(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\Models\Event $event
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(Event $event)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\Models\Event $event
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return \Illuminate\Http\JsonResponse
|
||||
*/
|
||||
public function update(Request $request, Event $event)
|
||||
public function update(EventRequest $request, Event $event)
|
||||
{
|
||||
//
|
||||
$this->authorize('update', $event);
|
||||
|
||||
$event->update($request->all());
|
||||
|
||||
return (new EventResource($event))
|
||||
->response()
|
||||
->setStatusCode(200);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,6 +76,10 @@ class EventController extends Controller
|
||||
*/
|
||||
public function destroy(Event $event)
|
||||
{
|
||||
//
|
||||
$this->authorize('delete', $event);
|
||||
|
||||
$event->delete();
|
||||
|
||||
return response([], 204);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -27,8 +27,9 @@ class EventRequest extends FormRequest
|
||||
'name' => 'required',
|
||||
'description' => 'nullable|string',
|
||||
'category_id' => 'required|exists:event_categories,id',
|
||||
'private' => 'boolean',
|
||||
'start_date' => 'required|date',
|
||||
'end_date' => 'date|after_or_equal:start_date',
|
||||
'end_date' => 'date|after_or_equal:start_date|nullable',
|
||||
'location' => 'string|nullable'
|
||||
];
|
||||
}
|
||||
|
||||
94
app/Policies/EventPolicy.php
Normal file
94
app/Policies/EventPolicy.php
Normal file
@@ -0,0 +1,94 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\Event;
|
||||
use App\User;
|
||||
use Illuminate\Auth\Access\HandlesAuthorization;
|
||||
|
||||
class EventPolicy
|
||||
{
|
||||
use HandlesAuthorization;
|
||||
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*
|
||||
* @param \App\User $user
|
||||
* @return mixed
|
||||
*/
|
||||
public function viewAny(User $user)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*
|
||||
* @param \App\User $user
|
||||
* @param \App\Models\Event $event
|
||||
* @return mixed
|
||||
*/
|
||||
public function view(User $user, Event $event)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*
|
||||
* @param \App\User $user
|
||||
* @return mixed
|
||||
*/
|
||||
public function create(User $user)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*
|
||||
* @param \App\User $user
|
||||
* @param \App\Models\Event $event
|
||||
* @return mixed
|
||||
*/
|
||||
public function update(User $user, Event $event)
|
||||
{
|
||||
return $user->id == $event->user_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*
|
||||
* @param \App\User $user
|
||||
* @param \App\Models\Event $event
|
||||
* @return mixed
|
||||
*/
|
||||
public function delete(User $user, Event $event)
|
||||
{
|
||||
return $user->id == $event->user_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore the model.
|
||||
*
|
||||
* @param \App\User $user
|
||||
* @param \App\Models\Event $event
|
||||
* @return mixed
|
||||
*/
|
||||
public function restore(User $user, Event $event)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the model.
|
||||
*
|
||||
* @param \App\User $user
|
||||
* @param \App\Models\Event $event
|
||||
* @return mixed
|
||||
*/
|
||||
public function forceDelete(User $user, Event $event)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -19,6 +19,7 @@ class AuthServiceProvider extends ServiceProvider
|
||||
'App\Models\Memo' => 'App\Policies\MemoPolicy',
|
||||
'App\Models\ToDoList' => 'App\Policies\ToDoListPolicy',
|
||||
'App\Models\Bookmark' => 'App\Policies\BookmarkPolicy',
|
||||
'App\Models\Event' => 'App\Policies\EventPolicy',
|
||||
];
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user