Did you try a composer dump-autoload?
Error: "Controller Not Defined" ... But I am staring right at it
I don't get it .. I'm staring right at the controller - yet, L5 tells me it is not defined. What dumb mistake might I have done ?
View:
{!! Form::open( ['action' => 'TestController@index', 'class'=>'form-horizontal']) !!}
Controller:
<?php namespace App\Http\Controllers;
use App\Http\Middleware\Authenticate;
use App\Http\Requests;
use Illuminate\Http\Request;
use App\Models\Contractor;
use Laracasts\Flash\Flash;
class TestController extends Controller
{
public function index()
{
return "Hello from Test";
}
}
Could you provide full exception message
@bobbybouwmann yup ran composer dump-autoload, made no difference
ErrorException in UrlGenerator.php line 576: Action App\Http\Controllers\TestController@index not defined. (View: /var/www/auburntree/resources/views/contractor_portal/portal_dashboard.blade.php)
@vincej - I can't remember, but you may have to specify the full namespaced path to the controller in your form tag.
Laravel provides a short-cut in your routes file, so that you don't have to do that. But I'm not sure if the same is true for form helpers. I'm thinking not.
Check that the filename of the controller has the same casing
I was thinking the same as @JeffreyWay, but based on the documentation here http://laravelcollective.com/docs/5.0/html
I don't think you have to specify the full namespace.
Still, give it a try and see.
Have you tried it through a route?
Thanks - but that didn't work either, In fact the 'action' tag fills in the the full App\Http\Controllers for you.
Looking at the Collective docs, their example is:
echo Form::open(array('action' => 'Controller@method'))
Most bizarrely I have other forms which using this syntax and they do work. So I'm a bit confused to say the least.
It randomly happens to me sometimes but not with the form, try to delete and create the class again.
I like how you titled this post its funny.
@vincej Hi, did you try using a URL and mapping a route? ??
Hi Jim - I just tried it through a route::resource that's what you mean... and I got the same error ... don't you just love computers :o)
Incase you missed it, did you check that you have TestController.php with the same capital letters?
Yeah this is going to wind up being one of those little tiny errors that you don't spot at first. Usually after taking a break, having a cup of coffee and going back I spot the error.
If @Snapey was correct, man up and own up to it. We have all done the exact same thing.
@vincej Perhaps this some other way to do it. But an action normally requires a URL. I know is a blade, but first question I ask is how is the Controller being mapped inside the blade. So I mean, did,you user a URL and map it in your route file. Or do you use a JS method and reference the URL there.
Try a regular get route, add a get method. And does that class you added have anything to do with it?
Heck I'm fixing to pop some popcorn.
I have tried it with a route:: resource, a get route, and of course placing the controller@method into the action tag as per Collective's docs. I get the same error every time.
Here is the bizarre thing. If I put into the action tag an existing controller I created, say last week, then everything works well. eg:
{!! Form::open( ['action' => 'ContractorEditController@confirm', 'class'=>'form-horizontal']) !!}
However, if I put a controller in which I created today, then it does not see it. It's like somehow Laravel does not register my controllers. But they look the same and alright to me.
Have you done an update recently? And of course you checked all your spelling capitalizations and that sort of thing as @Snapey suggested. Perhaps try another with a different name just to see what happens. I'm going after a second dish of popcorn now.
You can't buy this kind of entertainment this is a fun one. But we'll get it fixed.
Yup I have checkEd all the capitalisations about 200 times.
Update .... hmmm of what exactly ? I have done a clear-compile and a composer dump autoload
It just will not see my new controllers. I have tried deleting them and recreating them.
enjoy the popcorn - at this rate I'll be driving myself to drink !
Well no matter what let us know how you resolved it do not keep us in the dark here. Need some Pepsi now to wash down the popcorn.
Sure thing,
I have this new controller in a subdirectory of Controllers ... I wonder if that is part of the problem. But when I created a TestController in the main directory I had the problem.
so what's the path to your controller, because it should be the same as the namespace you declared?
"I have this new controller in a subdirectory of Controllers ... I wonder if that is part of the problem. But when I created a TestController in the main directory I had the problem."
So, should your example controller namespace look like this:
<?php namespace App\Http\Controllers\<your subdirectory>;
I just created a App/Controllers/Test/TestController.php
<?php namespace App\Http\Controllers\Test;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class TestController extends Controller {
public function index()
{
return "hello world";
}
Then added this route:
Route::get('test', 'Test\TestController@index');
And it works, but if I remove either or both Test\ from the route and/or controller I get the same error as you.
Hope that helps.
Ah @Snapey was right about the namespace.
Found this post through Google, and although it's old, my issue wasn't with namespaces. Even though I was using Controller@method, I forgot to create a corresponding route that uses Controller@method. Seems obvious when it works, hope it helps someone!
Please or to participate in this conversation.