0

I used this routes for either Laravel 5.1 and Laravel 5.3, and now when I'm using this type of route order it gives me the title error hope you can help me, you can find the code here :

Route::prefix('productos')->group(function () {

    'as' => 'products.index', 
    'uses' => 'ProductController@index'

    Route::get('crear',[
        'as' => 'products.create', 
        'uses' => 'ProductController@create'
    ]);
    Route::post('guardar',[
        'as' => 'products.store', 
        'uses' => 'ProductController@store'
    ]);
    // Editar, borrar
    Route::get('{id}',[
        'as' => 'products.destroy', 
        'uses' => 'ProductController@destroy'
    ]);
    Route::get('{id}/editar',[
        'as' => 'products.edit', 
        'uses' => 'ProductController@edit'
    ]);
    Route::put('{id}',[
        'as' => 'products.update', 
        'uses' => 'ProductController@update'
    ]);
});
Brandon Minnick
  • 13,342
  • 15
  • 65
  • 123
Julian Moreira
  • 129
  • 1
  • 5
  • 14
  • Possible duplicate of [PHP Parse/Syntax Errors; and How to solve them?](https://stackoverflow.com/questions/18050071/php-parse-syntax-errors-and-how-to-solve-them) – Qirel Aug 17 '17 at 13:55

2 Answers2

1

To use => you need to be in the context of an associative array in php. In your case you are using it inside a closure:

Route::prefix('productos')->group(function () {

    // This section is incorrect
    'as' => 'products.index', 
    'uses' => 'ProductController@index'
    // Because is not inside an array

    Route::get('crear',[
        'as' => 'products.create', 
        'uses' => 'ProductController@create'
    ]);
...

If I had to guess what you are looking for something like this:

Instead of

'as' => 'products.index', 
'uses' => 'ProductController@index'

You should have something like:

Route::get('listar',[
   'as' => 'products.index', 
   'uses' => 'ProductController@index'
]);

So the endpoint would be productos/listar.

Hope this helps you.

Asur
  • 3,727
  • 1
  • 26
  • 34
0

Syntax error

   'as' => 'products.index', 
  'uses' => 'ProductController@index'

Change it like this

 Route::get('products',[
       'as' => 'products.index', 
       'uses' => 'ProductController@index'
  ]);
Niklesh Raut
  • 34,013
  • 16
  • 75
  • 109