3
votes

I'm developing simple crude application using laravel 4.2. this is my controller method for edit/update.

class ProductsController extends BaseController{

    public function getEdit($id){

       $product=Products::find($id);
       $this->layout->content=View::make('products.edit',compact('product'));   
   }
}

this is the part of edit.blade.php file

 {{ Form::model($product, ['route' => ['products/update', $product->id], 'method' => 'patch']) }}

I define route for the ProductsController as follows in route.php file

 Route::controller ( 'products', 'ProductsController');

when i try to edit product(http://localhost:8000/products/5/edit)

it says Route [products/update] not defined.

this is my edit link

 <a class="btn btn-small btn-info" href="{{ URL::to('products/' . $product->id . '/edit') }}">Edit </a>

what is the reason for this error? i have define patchUpdate() function on product contraller.

2

2 Answers

3
votes

You are using a route controller, not a resourceful controller - so there are no 'named' routes.

You could do this

{{ Form::model($product, ['action' => 'ProductsController@putEdit', $product->id], 'method' => 'patch']) }}
1
votes

Add following line your routes.php file

Route::model('products', 'Product');
Route::resource('products', 'ProductsController');

and also change what @The Shift Exchange has suggested

products.update not products/update

change also

 <a class="btn btn-small btn-info" href="{{ URL::to('products/getEdit/'. $product->id) }}">Edit </a>