1

I'm working on a form with Laravel 5, following up a tutorial from Openclassropms which is about Laravel 4, and that really gave me a hard time.

Anyway, I'm trying to change these lines in my routes.php file:

Route::get('users' , 'UsersController@getInfos');
Route::post('users', 'UsersController@postInfos');

with this line :

Route::controller('users', 'UsersController');

but doing so breaks my form, I can still see the input text area but submitting it gives me the following error :

NotFoundHttpException in RouteCollection.php line 145

Here are my controllers and templates:

<?php namespace App\Http\Controllers;
use Illuminate\Support\Facades\Input;
class UsersController extends Controller {

    public function getInfos()
    {
        return \View::make('infos');
    }

    public function postInfos()
    {
        echo 'The name is ' . Input::get('nom');
    }

}

@extends('tempform')

and

@section('content')
    {!! Form::open(array('url'=>'users')) !!}
        {!! Form::label('nom', 'Enter your name:') !!}
        {!! Form::text('nom') !!}
        {!! Form::submit('Submit') !!}
    {!! Form::close() !!}
@stop

Also, I use a different url once I make the change as stated initially in the tutorial: gappsl/users >> gappsl/users/info

3
  • Laravel 5 is really quite different to Laravel 4.*, I would recommend not following a Laravel 4 tutorial unless you're going to use version 4 of the framework. Commented Feb 27, 2015 at 10:12
  • Do you know of any good beginner-friendly tutorials for Laravel 5? and moreover, should I keep working on Laravel 5 or make the switch to version 4.2 in your opinion? Commented Feb 27, 2015 at 12:23
  • There are a few Laravel 5 from scratch tutorials around but it was only officially released Feb 2015. A google should find them. I would learn 5, there seems little point putting time into 4 at this point. Commented Feb 27, 2015 at 12:28

3 Answers 3

2

You have to create a new method in your controller called getIndex() or postIndex() depending on which HTTP verb you will be using. This way the /users route will work correctly.

Sign up to request clarification or add additional context in comments.

Comments

0

If you are using Route::controller() method then it is always looking for the functions starting with the HTTP Verb.

In your case, If you want to point the postInfos() through your form. Then you need to change your form definition to this:

{!! Form::open(array('url'=>'users/infos', 'method'=>'POST')) !!}

Or

If you have any confusions regarding which routes to use, then simply go to command line within your application root directory and type php artisan route:list.

There you can find which URI points to which method with full controller path.

Comments

-1

You need to change the line form open to :

  {!! Form::open(array('url'=>'users/post-infos')) !!}

to address your postInfos() function

4 Comments

Gonna try this one as well, it will probably come in handy too, thanks Edwin.
Actually it does not work like @EdwinKrause said. If you want to call for example postInfos route you have to use /users/infos path with POST method. Analogically if you want to call patchHelloWorld you should use /users/hello-world with PATCH method. Hopefully it helps.
I was thinking this myself and you're right Maksym it actually worked with /users/infos, not with users/post-infos like Edwin pointed out, but he pointed me to the right direction and now I'm kinda getting the grasp of it. Thank you for your help!!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.