Saya baru saja melakukannya, untuk menambahkan metode "hapus" DAPATKAN.
Setelah membuat file, Anda hanya perlu menambahkan
'AntonioRibeiro\Routing\ExtendedRouterServiceProvider',
ke 'penyedia' di aplikasi / config.php Anda
Edit alias Rute dalam file yang sama ini:
'Route' => 'Illuminate\Support\Facades\Route',
mengubahnya menjadi
'Route' => 'AntonioRibeiro\Facades\ExtendedRouteFacade',
Dan pastikan file-file itu sedang dimuat secara otomatis, mereka harus ada di beberapa direktori yang Anda miliki di composer.json Anda (bagian "pengisian otomatis").
Maka Anda hanya perlu:
Route::resource('users', 'UsersController');
Dan ini (lihat baris terakhir) adalah hasilnya jika Anda menjalankan php artisan routes
:
Itu adalah file sumber saya:
ExtendedRouteFacade.pas
<?php namespace AntonioRibeiro\Facades;
use Illuminate\Support\Facades\Facade as IlluminateFacade;
class ExtendedRouteFacade extends IlluminateFacade {
/**
* Determine if the current route matches a given name.
*
* @param string $name
* @return bool
*/
public static function is($name)
{
return static::$app['router']->currentRouteNamed($name);
}
/**
* Determine if the current route uses a given controller action.
*
* @param string $action
* @return bool
*/
public static function uses($action)
{
return static::$app['router']->currentRouteUses($action);
}
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor() { return 'router'; }
}
ExtendedRouter.pas
<?php namespace AntonioRibeiro\Routing;
class ExtendedRouter extends \Illuminate\Routing\Router {
protected $resourceDefaults = array('index', 'create', 'store', 'show', 'edit', 'update', 'destroy', 'delete');
/**
* Add the show method for a resourceful route.
*
* @param string $name
* @param string $base
* @param string $controller
* @return void
*/
protected function addResourceDelete($name, $base, $controller)
{
$uri = $this->getResourceUri($name).'/{'.$base.'}/destroy';
return $this->get($uri, $this->getResourceAction($name, $controller, 'delete'));
}
}
ExtendedRouteServiceProvider.pas
<?php namespace AntonioRibeiro\Routing;
use Illuminate\Support\ServiceProvider;
class ExtendedRouterServiceProvider extends ServiceProvider {
/**
* Indicates if loading of the provider is deferred.
*
* @var bool
*/
protected $defer = true;
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->app['router'] = $this->app->share(function() { return new ExtendedRouter($this->app); });
}
/**
* Get the services provided by the provider.
*
* @return array
*/
public function provides()
{
return array('router');
}
}
::resource
jika Anda mendapatkan pesan kesalahan, "Tidak ada hasil query untuk model".