Reputation: 2967
I'm really new to Laravel, and am trying to just get a Form to work in general.
So I have a page (admin/index) that just have a form to it that has the route that maps to AdminController@test. The form submits fine but then I get a NotFoundHttpException. :(
The code for the form builder in index.blade.php is:
@extends('layouts.master')
@section('title')
Admin
@stop
@section('content')
{{ Form::open(array('route' => 'test', 'method' => 'get')) }} <!-- Works with AdminController@index -->
{{ Form::text('info') }}
{{ Form::close() }}
@stop
The route in question is:
Route::get('/admin/test/' , array( 'as' => 'test' ,
'uses' => 'AdminController@test'));
And the controller in question is:
class AdminController extends BaseController{
public function index(){
return View::make('admin.index');
}
public function test(){
error_log('Yay!');
}
}
Like I said, simple form on admin/index , submits, but it doesn't make it to the controller, just to the NotFoundHttpException.
Edit: The form's HTML looks like this:
<form method="GET" action="http://localhost/showknowledge/admin/test/"
accept-charset="UTF-8">
<input name="info" type="text">
</form>
Upvotes: 1
Views: 1393
Reputation: 10794
It might be clearer to move your Routing logic into the AdminController
and use a RESTful controller:
in routes.php
add this, and remove the two route definitions for /admin/index
and /admin/test
:
Route::controller('admin' , 'AdminController');
This directs all requests to admin/
to your AdminController. now you need to rename your functions to include the HTTP verb (GET, POST or any), and the next component of your route:
public function getIndex() // for GET requests to admin/index
{
//blha blah blah
}
public function getTest() // for GET requests to admin/test
{
//blha blah blah
}
Finally, update your form to use that route directly through the action
keyword:
{{ Form::open(array('action' => 'AdminController@getTest', 'method' => 'get')) }}
note, using missingMethod()
to catch unhandled requests is really useful too, more info in the Laravel docs: http://laravel.com/docs/controllers#handling-missing-methods
Hope that helps
Upvotes: 3