vendredi 27 février 2015

How to use RESTful controller within Laravel 5

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


Aucun commentaire:

Enregistrer un commentaire