WilliamD.
WilliamD.

Reputation: 119

Laravel 4 generate url error

I'm new to Laravel 4 and I get this error : Some mandatory parameters are missing ("id") to generate a URL for route "cat_edit".

Here's my route :

Route::get('/category/{id}/edit', array(
    'as' => 'cat_edit',
    'uses' => 'CategoryController@editAction'
))->where('id', '[0-9]+');

Here's my controller :

public function editAction($id){

    $category = Category::find($id);
    $categories = Category::all();

    return View::make('categories.edit', array(
        'category'    =>  $category ,
        'categories'  =>  $categories,
    ));
}

And finally my view :

@extends('layouts.main')

@section('title')
    Edit category
@stop

@section('content')
<h1>Add a Category</h1>

{{ Form::open(array('action' => 'CategoryController@editAction')) }}

{{ Form::form_lab('text', 'name', 'Name') }}

{{ Form::form_lab('textarea', 'description', 'Description') }}

{{ Form::form_select('parent', 'Parent', $categories) }}



<div class="form-actions">
    {{ Form::form_button('Validate') }}
</div>

{{ Form::close() }}

@stop

I've been searching for hours but I can't see where I'm wrong. All, my other routes are working fine.

Thanks !

Upvotes: 0

Views: 1465

Answers (1)

DerLola
DerLola

Reputation: 3918

You could rewrite the Form::open to use URL::action instead. See Laravel 4: What to pass as parameters to the Url class? on how to pass parameters to URL::action.

Example:

{{ Form::open(array('url' => URL::action('CategoryController@editAction', ['123']) )) }}

Upvotes: 2

Related Questions