Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Route [Controller@method] not defined

Tags:

php

laravel-4

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?

like image 288
lasagne Avatar asked Jan 04 '14 10:01

lasagne


People also ask

How to define routes in Laravel?

All Laravel routes are defined in your route files, which are located in the routes directory. These files are automatically loaded by your application's App\Providers\RouteServiceProvider . The routes/web.php file defines routes that are for your web interface.

What is controller route in Laravel?

For route controller method we have to define only one route. In get or post method we have to define the route separately. And the resources method is used to creates multiple routes to handle a variety of Restful actions. Here the Laravel documentation about this.

What is route model Binding in Laravel?

Route model binding in Laravel provides a mechanism to inject a model instance into your routes.


1 Answers

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'));
like image 79
Anam Avatar answered Sep 22 '22 09:09

Anam