The issue you're encountering is likely due to the incorrect use of curly braces in your route definition. In Laravel, when defining route parameters, you should use curly braces without the dollar sign. Here's how you can fix it:
Correct Route Definition
In your web.php, update the route definition to use the correct syntax for route parameters:
Route::patch('/jobs/{id}', function ($id) {
// Validate the request
request()->validate([
'title' => ['required', 'min:3'],
'salary' => ['required']
]);
// Find the job by ID
$job = Job::findOrFail($id);
// Update the job with the new data
$job->update([
'title' => request('title'),
'salary' => request('salary')
]);
// Redirect to the updated job's page
return redirect('/jobs/' . $job->id);
});
Additional Considerations
-
Form Method: Ensure that your form in the Blade template is using the
PATCHmethod. You can do this using the@methoddirective in a form that usesPOST:<form action="/jobs/{{ $job->id }}" method="POST"> @csrf @method('PATCH') <!-- form fields here --> <button type="submit">Update</button> </form> -
CSRF Token: Make sure you include the CSRF token in your form using
@csrf. -
Route List: After making these changes, run
php artisan route:listto ensure that the route is correctly registered.
By correcting the route parameter syntax and ensuring your form is set up correctly, the PATCH method should be supported for your route.