Skip to content

Commit

Permalink
Fix csrf issue for content update routes
Browse files Browse the repository at this point in the history
  • Loading branch information
changeweb committed Aug 13, 2021
1 parent a6497ac commit f796452
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 21 deletions.
6 changes: 3 additions & 3 deletions app/Http/Controllers/CertificateController.php
Expand Up @@ -69,12 +69,12 @@ public function edit(Certificate $certificate)
/**
* Update the specified resource in storage.
*
* @param int $id
* @param Request $request
* @return \Illuminate\Http\Response
*/
public function update($id)
public function update(Request $request)
{
$tb = Certificate::find($id);
$tb = Certificate::find($request->id);
$tb->active = 0;
$tb->save();
return back()->with('status',__('File removed'));
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/EventController.php
Expand Up @@ -73,12 +73,12 @@ public function edit($id)
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @param Request $request
* @return \Illuminate\Http\Response
*/
public function update($id)
public function update(Request $request)
{
$tb = Event::find($id);
$tb = Event::find($request->id);
$tb->active = 0;
$tb->save();
return back()->with('status','File removed');
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/NoticeController.php
Expand Up @@ -72,12 +72,12 @@ public function edit($id)
/**
* Update the specified resource in storage.
*
* @param int $id
* @param Request $request
* @return \Illuminate\Http\Response
*/
public function update($id)
public function update(Request $request)
{
$tb = Notice::find($id);
$tb = Notice::find($request->id);
$tb->active = 0;
$tb->save();
return back()->with('status',__('File removed'));
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/RoutineController.php
Expand Up @@ -120,12 +120,12 @@ public function edit($id)
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @param Request $request
* @return \Illuminate\Http\Response
*/
public function update($id)
public function update(Request $request)
{
$tb = Routine::find($id);
$tb = Routine::find($request->id);
$tb->active = 0;
$tb->save();
return back()->with('status',__('File removed'));
Expand Down
6 changes: 3 additions & 3 deletions app/Http/Controllers/SyllabusController.php
Expand Up @@ -95,12 +95,12 @@ public function edit($id)
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @param Request $request
* @return \Illuminate\Http\Response
*/
public function update($id)
public function update(Request $request)
{
$tb = Syllabus::find($id);
$tb = Syllabus::find($request->id);
$tb->active = 0;
$tb->save();
return back()->with('status',__('File removed'));
Expand Down
8 changes: 7 additions & 1 deletion resources/views/components/uploaded-files-list.blade.php
Expand Up @@ -34,7 +34,13 @@
@endif
<td>{{($file->active === 1)?'Yes':'No'}}</td>
<td>
<a href="{{url('academic/remove/'.$upload_type.'/'.$file->id)}}" class="btn btn-danger btn-sm" role="button"><i class="material-icons">delete</i> @lang('Remove')</a>
<a href="{{url('academic/remove/'.$upload_type)}}" onclick="event.preventDefault();
document.getElementById('remove-file-'+{{$file->id}}).submit();" class="btn btn-danger btn-sm" role="button"><i class="material-icons">delete</i> @lang('Remove')</a>

<form id="remove-file-{{$file->id}}" action="{{url('academic/remove/'.$upload_type)}}" method="POST" style="display: none;">
{{ csrf_field() }}
<input type="hidden" name="id" value="{{$file->id}}">
</form>
</td>
</tr>
@endforeach
Expand Down
10 changes: 5 additions & 5 deletions routes/web.php
Expand Up @@ -100,11 +100,11 @@
Route::get('routine', 'RoutineController@index');
Route::get('routine/{section_id}', 'RoutineController@create');
Route::prefix('remove')->name('remove.')->group(function () {
Route::get('syllabus/{id}', 'SyllabusController@update');
Route::get('notice/{id}', 'NoticeController@update');
Route::get('event/{id}', 'EventController@update');
Route::get('certificate/{id}', 'CertificateController@update');
Route::get('routine/{id}', 'RoutineController@update');
Route::get('syllabus', 'SyllabusController@update');

This comment has been minimized.

Copy link
@am0o0

am0o0 Aug 13, 2021

Route::POST('syllabus', 'SyllabusController@update');

This comment has been minimized.

Copy link
@changeweb

changeweb Aug 13, 2021

Author Owner

@amammad Oops! I forgot to update other routes. I changed only 'event update' route to post.
Now I have updated them in a new commit. Thank you for your help.

Route::get('notice', 'NoticeController@update');

This comment has been minimized.

Copy link
@am0o0

am0o0 Aug 13, 2021

Route::POST('notice', 'NoticeController@update');

Route::post('event', 'EventController@update');
Route::get('certificate', 'CertificateController@update');

This comment has been minimized.

Copy link
@am0o0

am0o0 Aug 13, 2021

Route::POST('certificate', 'CertificateController@update');

Route::get('routine', 'RoutineController@update');

This comment has been minimized.

Copy link
@am0o0

am0o0 Aug 13, 2021

Route::POST('routine', 'RoutineController@update');

});
});

Expand Down

0 comments on commit f796452

Please sign in to comment.