v Sugumar v Sugumar - 5 months ago 153
PHP Question

Laravel : Overriding route for specific route in voyager

I am trying to override a route for creating a row. (posting, not viewing)

http://lsapp.dev/admin/cpu-speed/create

In web.php

I modified

Route::group(['prefix' => 'admin'], function () {
Voyager::routes();
Route::post('/cpu-speed',['uses' => 'Admin\Mobiles\CPUSpeedController@store', 'as' => 'store']);

});


Also I created Controller

namespace App\Http\Controllers\Admin\Mobiles;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;


class CPUSpeedController extends Controller
{
public function store(){
return 'hello';
}

public function create(){
return 'create';
}
}


But it throws the following error:


ErrorException (E_ERROR) Route [voyager.cpu-speed.store] not defined.
(View:
/var/www/html/lsapp/vendor/tcg/voyager/resources/views/bread/edit-add.blade.php)

Answer Source

It appears you are only naming it store here:

Route::post('/cpu-speed',['uses' => 'Admin\Mobiles\CPUSpeedController@store',  'as' => 'store']);

It should probably be:

Route::post('/cpu-speed',['uses' => 'Admin\Mobiles\CPUSpeedController@store',  'as' => 'voyager.cpu-speed.store']);

I'm not entirely sure this will work, since it may be interpreted and descend into the Voyager package, rather than just reading your web.php file, but I believe it will do what you like.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download