laravel 5 urlgenerator with Form::open route with Route Annotations

2.7k views Asked by At

I'm using Laravel 5 with Route Annotations. (The app\Http\route.php will be automaticaly deleted). For video about Route Annotations, you may have a look at https://www.youtube.com/watch?v=sOvgw40Dg4A

I build a ContactController.php with php artisan make:controller ContactController

And at store() function, I add return view('pages.contact'); to re-input another contact data.

When I give the script below on my pages\contact.blade.php :

{!! Form::open(['route'=>'contact.store']) !!}

It allways return error as below :

ErrorException in UrlGenerator.php line 237: Route [contact.store] not defined. (View: D:\www\mycontact\resources\views\pages\contact.blade.php)

which refer to :

public function route($name, $parameters = array(), $absolute = true)
{
  if ( ! is_null($route = $this->routes->getByName($name)))
  {
      return $this->toRoute($route, $parameters, $absolute);
  }

  throw new InvalidArgumentException("Route [{$name}] not defined.");
}

But when I change into :

{!! Form::open(['url'=>'contact']) !!}

it works normally.

How to fix my laravel so I can use the route ?

Below are the things that I have done :

composer require illuminate/html

At config\app.php , I add : 'Form' => 'Illuminate\Html\FormFacade' so I can use the {!! Form:: !!}

Then I execute the following command :

composer update
composer dump-autoload 
php artisan dump
php artisan clear-compiled
php artisan dump-autoload
php artisan optimize
php artisan route:clear
php artisan route:scan
php artisan route:list 

So... How to fix my laravel so in my blade, I can use {!! Form::open(['route'=>'contact.store']) !!} instead {!! Form::open(['url'=>'contact']) !!} ?

PS: I use XAMPP on Windows 7 Pro 64bit. And I already read : http://laravel.io/forum/10-11-2014-forms-doesnt-work-in-laravel-5

For my steps on Route Annotations, at App\Providers\RouteServiceProvider.php , I add my controllers with in

protected $scan = [
  'App\Http\Controllers\HomeController', // for http://localhost/myl5/
  'App\Http\Controllers\ContactController',  //  for http://localhost/myl5/contact
];
0

There are 0 answers