Hello @jwavess ,
can we see your code for the ::resource please?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
When I write my routes out by hand everything runs smoothly, when I try and use "resource" instead I get this error.
NotFoundHttpException in RouteCollection.php line 16
Here is my hand written routes, these routes make everything run smoothly, why will resource not work.
Route::get('food/create', 'FoodController@create');
Route::post('food/post', 'FoodController@store');
Route::get('food/{id}', 'FoodController@index');
Below is the rest of my code from the other files, and if you would like for my to show you what "php artisan route:list" brings up when I hand write the routes and when "resource" writes them, I would be more than happy to show you in a comment.
(In the controller file)
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Food;
use App\Http\Requests\CreateFoodRequest;
class FoodController extends Controller
{
public function index($id) {
$food = Food::find($id);
return view('index')->with('food', $food);
}
public function create() {
return view('vendor.create');
}
public function store(CreateFoodRequest $request) {
$input = $request->all();
$food = Food::create($input);
return redirect('food/'.$food->id);
}
}
(in the index file)
@extends('app')
@section('body')
<h1>Foods!</h1>
<a href ="food/{!! $food->id !!}"><h2>{{ $food->vegetables }}</h2></a>
<a href ="food/{!! $food->id !!}"><h2>{{ $food->fruit }}</h2></a>
<a href ="food/{!! $food->id !!}"><h2>{{ $food->grains }}</h2></a>
<a href ="food/{!! $food->id !!}"><h2>{{ $food->meat }}</h2></a>
<a href ="food/{!! $food->id !!}"><h2>{{ $food->sugar }}</h2></a>
@stop('body')
(In the create file)
@extends('app')
@section('body')
{!! Form::open(['url'=>'food/post']) !!}
<div class="form-group">
{!! Form::label('vegetables', 'Vegetable item:') !!}
{!! Form::text('vegetables', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('fruit', 'Fruit item:') !!}
{!! Form::text('fruit', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('meat', 'Meat item:') !!}
{!! Form::text('meat', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('grains', 'Grain item:') !!}
{!! Form::text('grains', null, ['class' => 'form-control']) !!}
</div>
<div class="form-group">
{!! Form::label('sugar', 'Sugar item:') !!}
{!! Form::text('sugar', null, ['class' => 'form-control']) !!}
</div>
<div>
{!! Form::submit('Add Food items', ['class' => 'btn btn-primary form-control']) !!}
{!! Form::close() !!}
</div>
@if($errors->any())
<ul class="alert alert-danger">
@foreach($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>
@endif
@stop('body')
Seth
Your form is posting to 'food/post' but when using a resource controller, that route doesn't exist. So, Laravel assumes that 'post' is a variable and is trying to hit food/{food}. However, this route does not allow post requests. That is why you are getting this error.
When using resource controllers, you have to follow conventions. Your form should be posting to 'food'.
Please or to participate in this conversation.