2017-01-25 12 views
2

Я пытаюсь сделать rest api с dingo для laravel 5.3. У меня есть установка dingo в моем проекте и создан маршрут api, подобный этому для теста.Звонок на неопределенный метод Illuminate Routing Route :: getUri()

$api->version('v1', function ($api) { 
    $api->get('hello',function(){ 

     return "hello"; 
    }); 

}); 

Но когда я бегу http://localhost:8000/api/hello

Тогда

{ 
message: "Call to undefined method Illuminate\Routing\Route::getUri()", 
code: 1, 
status_code: 500, 
debug: { 
line: 98, 
file: "C:\xampp\htdocs\apiTest\vendor\dingo\api\src\Routing\Adapter\Laravel.php", 
class: "Symfony\Component\Debug\Exception\FatalErrorException", 
trace: [ 
"#0 {main}" 
] 
} 
} 

показано.

я искал и нашел это решение Call to undefined method Illuminate\Routing\Route::get()

но когда я использовал

use Illuminate\Support\Facades\Route; 

, то эта проблема, показанную

FatalErrorException in Laravel.php line 116: 
Call to undefined method Illuminate\Support\Facades\Route::where() 

Это файл Laravel.php

<?php 

namespace Dingo\Api\Routing\Adapter; 

use Illuminate\Http\Request; 
use Illuminate\Routing\Route; 
use Illuminate\Routing\Router; 
use Illuminate\Routing\RouteCollection; 
use Dingo\Api\Contract\Routing\Adapter; 
use Dingo\Api\Exception\UnknownVersionException; 

class Laravel implements Adapter 
{ 
    /** 
    * Laravel router instance. 
    * 
    * @var \Illuminate\Routing\Router 
    */ 
    protected $router; 

    /** 
    * Array of registered routes. 
    * 
    * @var array 
    */ 
    protected $routes = []; 

    /** 
    * Old routes already defined on the router. 
    * 
    * @var \Illuminate\Routing\RouteCollection 
    */ 
    protected $oldRoutes; 

    /** 
    * Create a new laravel routing adapter instance. 
    * 
    * @param \Illuminate\Routing\Router $router 
    * 
    * @return void 
    */ 
    public function __construct(Router $router) 
    { 
     $this->router = $router; 
    } 

    /** 
    * Dispatch a request. 
    * 
    * @param \Illuminate\Http\Request $request 
    * @param string     $version 
    * 
    * @return mixed 
    */ 
    public function dispatch(Request $request, $version) 
    { 
     if (! isset($this->routes[$version])) { 
      throw new UnknownVersionException; 
     } 

     $routes = $this->mergeExistingRoutes($this->routes[$version]); 

     $this->router->setRoutes($routes); 

     return $this->router->dispatch($request); 
    } 

    /** 
    * Merge the existing routes with the new routes. 
    * 
    * @param \Illuminate\Routing\RouteCollection $routes 
    * 
    * @return \Illuminate\Routing\RouteCollection 
    */ 
    protected function mergeExistingRoutes(RouteCollection $routes) 
    { 
     if (! isset($this->oldRoutes)) { 
      $this->oldRoutes = $this->router->getRoutes(); 
     } 

     foreach ($this->oldRoutes as $route) { 
      $routes->add($route); 
     } 

     return $routes; 
    } 

    /** 
    * Get the URI, methods, and action from the route. 
    * 
    * @param mixed     $route 
    * @param \Illuminate\Http\Request $request 
    * 
    * @return array 
    */ 
    public function getRouteProperties($route, Request $request) 
    { 
     return [$route->getUri(), $route->getMethods(), $route->getAction()]; 
    } 

    /** 
    * Add a route to the appropriate route collection. 
    * 
    * @param array $methods 
    * @param array $versions 
    * @param string $uri 
    * @param mixed $action 
    * 
    * @return \Illuminate\Routing\Route 
    */ 
    public function addRoute(array $methods, array $versions, $uri, $action) 
    { 
     $this->createRouteCollections($versions); 

     $route = new Route($methods, $uri, $action); 
     $route->where($action['where']); 

     foreach ($versions as $version) { 
      $this->routes[$version]->add($route); 
     } 

     return $route; 
    } 

    /** 
    * Create the route collections for the versions. 
    * 
    * @param array $versions 
    * 
    * @return void 
    */ 
    protected function createRouteCollections(array $versions) 
    { 
     foreach ($versions as $version) { 
      if (! isset($this->routes[$version])) { 
       $this->routes[$version] = new RouteCollection; 
      } 
     } 
    } 

    /** 
    * Get all routes or only for a specific version. 
    * 
    * @param string $version 
    * 
    * @return mixed 
    */ 
    public function getRoutes($version = null) 
    { 
     if (! is_null($version)) { 
      return $this->routes[$version]; 
     } 

     return $this->routes; 
    } 

    public function getIterableRoutes($version = null) 
    { 
     return $this->getRoutes($version); 
    } 

    /** 
    * Set the routes on the adapter. 
    * 
    * @param array $routes 
    * 
    * @return void 
    */ 
    public function setRoutes(array $routes) 
    { 
     $this->routes = $routes; 
    } 

    /** 
    * Prepare a route for serialization. 
    * 
    * @param mixed $route 
    * 
    * @return mixed 
    */ 
    public function prepareRouteForSerialization($route) 
    { 
     $route->prepareForSerialization(); 

     return $route; 
    } 

    /** 
    * Gather the route middlewares. 
    * 
    * @param \Illuminate\Routing\Route $route 
    * 
    * @return array 
    */ 
    public function gatherRouteMiddlewares($route) 
    { 
     return $this->router->gatherRouteMiddlewares($route); 
    } 
} 

Есть ли решение? Благодаря

+0

вы можете сделать 'PHP мастерового маршрута: list' и посмотреть, что он возвращается. вы могли бы нанести неправильный url –

+0

да, но первая ошибка показывает –

+0

У вас есть правильные настройки dingo' из https://github.com/dingo/api/wiki/Configuration –

ответ

2

Использования $route->uri()

InstEd из $route->getUri()

создать запрос тянуть к Динго апи после обновления этого

+0

Dingo api уже обновил код, просто запустите 'composer update' –