Reputation: 641
I'm trying to create a form with a corresponding controller method which adds a new record to the DB. Laravel Version is 4.1
app/views/projects.blade.php
<tr>
{{Form::open(array('action' => 'ProjectController@createProject', 'method' => 'post'))}}
<td>{{Form::text('project_number')}}</td>
<td>{{Form::text('title')}}</td>
<td>{{Form::text('client')}}</td>
<td>{{Form::text('comment')}}</td>
<td>
{{Form::file('xmlfile')}}<br />
{{Form::submit('Hinzufügen',array('class' => 'blue'))}}
</td>
{{ Form::close() }}
</tr>
app/controllers/ProjectController
<?php
class ProjectController extends BaseController {
public function listProjects(){
$projects = Project::all();
return View::make('projects',array('projects' => $projects));
}
public function createProject(){
/* handling the form data later
.
.
.
*/
return "Hello";
}
}
?>
Routes.php
// Project Routes
Route::get('/projects', array('as' => 'listProjects', 'uses' => 'ProjectController@listProjects'));
Route::get('/projects/{id}', array('as' => 'actionProject', 'uses' => 'ProjectController@actionProject'));
// Canal Routes
Route::get('/canals', array('as' => 'listCanals', 'uses' => 'CanalController@listCanals'));
Error Message
ErrorException Route [ProjectController@createProject] not defined. (View: /var/www/virtual/hwoern/laravel/app/views/projects.blade.php)
Show the existing projects with the list method in the projects view works fine. What have I overlooked?
Upvotes: 14
Views: 19063
Reputation: 12199
You have received the Route [ProjectController@createProject] not defined
because you haven't created any post route for action ProjectController@createProject
yet.
You have to define the following route:
route.php
Route::post('new-project', array('uses' => 'ProjectController@createProject'));
Upvotes: 29