Your posting to the ProfilesController in your routes file.
Route::patch('/c/{procedure}', 'ProfilesController@update');
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hey Guys,
I'm new to laravel and I keep stumbling on this 403 not authorized error when I try to run an update function in one of my controllers.
I created a model/controller for "Procedures" and was able to create a form to allow the user to make and store these in the database and show them on the front-end, however I'm stuck on creating the "edit" area.
Here's my controller:
<?php
namespace App\Http\Controllers;
use App\User;
use App\Procedure;
use Illuminate\Http\Request;
use Intervention\Image\Facades\Image;
class ProceduresController extends Controller
{
public function __construct()
{
$this->middleware('auth');
}
public function index()
{
$user = auth()->user();
return view('procedures.index', compact('user'));
}
public function edit(\App\Procedure $procedure)
{
return view('procedures.edit', compact('procedure'));
}
public function update()
{
$data = request()->validate([
'title' => 'required',
'category' => 'required',
'item' => 'required',
'image' => ['required','image'],
]);
$imagePath =request('image')->store('uploads','public');
$image = Image::make(public_path("storage/{$imagePath}"))->fit(500, 250);
$image->save();
auth()->user()->procedures()->update([
'title' => $data['title'],
'category' => $data['category'],
'item' => $data['item'],
'image' => $imagePath,
]);
}
public function create()
{
return view('procedures.create');
}
public function store()
{
$data = request()->validate([
'title' => 'required',
'category' => 'required',
'item' => 'required',
'image' => ['required','image'],
]);
$imagePath =request('image')->store('uploads','public');
$image = Image::make(public_path("storage/{$imagePath}"))->fit(500, 250);
$image->save();
auth()->user()->procedures()->create([
'title' => $data['title'],
'category' => $data['category'],
'item' => $data['item'],
'image' => $imagePath,
]);
return redirect('/profile/' . auth()->user()->id);
}
public function show(\App\Procedure $procedure)
{
return view('procedures.show', compact('procedure'));
}
}
Here's my Routes file:
<?php
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Auth::routes();
Route::get('/email', function (){
return new \App\Mail\NewUserWelcomeMail();
});
Route::get('/', 'HomeController@index');
Route::get('/c', 'ProceduresController@index');
Route::get('/c/create', 'ProceduresController@create');
Route::get('/c/{procedure}', 'ProceduresController@show');
Route::get('/c/{procedure}/edit', 'ProceduresController@edit');
Route::patch('/c/{procedure}', 'ProfilesController@update');
Route::post('/c', 'ProceduresController@store');
Route::get('/profile/{user}', 'ProfilesController@index')->name('profile.show');
Route::get('/profile/{user}/edit', 'ProfilesController@edit')->name('profile.edit');
Route::patch('/profile/{user}', 'ProfilesController@update')->name('profile.update');
Here's my edit.blade.php file:
@extends('layouts.app')
@section('content')
<div class="container">
<form action="/c/{{ $procedure->id }}" enctype="multipart/form-data" method="post">
@method('PATCH')
@csrf
<div class="row">
<div class="col-8 offset-2">
<div class="row">
<h1>Edit Case</h1>
</div>
<div class="form-group row">
<label for="Title" class="col-md-4 col-form-label">Case Title</label>
<input id="title"
type="text"
class="form-control @error('title') is-invalid @enderror"
name="title" value="{{ old('title') ?? $procedure->title }}"
autocomplete="title" autofocus>
@error('title')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
<div class="row">
<label for="Category" class="col-md-4 col-form-label">Case Category</label>
<input id="category"
type="category"
class="form-control @error('category') is-invalid @enderror"
name="category" value="{{ old('category') ?? $procedure->category}}"
autocomplete="category" autofocus>
@error('category')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
<div class="row">
<label for="Item" class="col-md-4 col-form-label">Item</label>
<input id="item"
type="item"
class="form-control @error('item') is-invalid @enderror"
name="item" value="{{ old('item') ?? $procedure->item}}"
autocomplete="item" autofocus>
@error('item')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
@enderror
</div>
<div class="row">
<label for="image" class="col-md-4 col-form-label">Change Mayo Stand Image</label>
<img src="/storage/{{ $procedure->image }}" width="500px">
<input type="file" class="form-control-file" id="image" name="image">
@error('image')
<strong>{{ $message }}</strong>
@enderror
</div>
<div class="row pt-4">
<button class="btn btn-primary">Update Case</button>
</div>
</div>
</div>
</form>
</div>
@endsection
I am able to access the edit page and see the info but when I click on the "Update Case" button it gives me the "403 - This action is unauthorized" error. I have tried all day to figure this out and still have not been able to... Any help would be greatly appreciated!
Please or to participate in this conversation.