消费Web服务laravel

消费Web服务laravel,laravel,rest,web-services,Laravel,Rest,Web Services,我在laravel有两个项目,一个只有我的愿景(AppView),另一个是web服务(AppWs),在我的web服务中,我有以下路线 路线项目应用程序 路由::组(['prefix'=>'api'],函数(){ 当我访问 它会返回一个包含所有数据的数组,直到找到为止 在我的另一个项目中,我有一个TypeProjectController控制器和我的index()方法(AppView),那么我如何检索要在这里加载的webservice数据呢 编辑 负责操作数据的AppWs public funct

我在laravel有两个项目,一个只有我的愿景(AppView),另一个是web服务(AppWs),在我的web服务中,我有以下路线 路线项目应用程序 路由::组(['prefix'=>'api'],函数(){

当我访问

它会返回一个包含所有数据的数组,直到找到为止

在我的另一个项目中,我有一个TypeProjectController控制器和我的index()方法(AppView),那么我如何检索要在这里加载的webservice数据呢

编辑

负责操作数据的AppWs

public function All(){
    return $this->ModelTipoProjeto->paginate(5);
  }
AppView负责显示数据 路由::资源('/Painel/TipoProjeto',Painel\TipoProjetoController');

 public function index()
    {
        $getData = `http://localhost/WebServiceApp/public/api/user/tipoprojeto/` // <~~

        return view('Painel.TipoProjeto.index');
    }
公共功能索引()
{

$getData=`http://localhost/WebServiceApp/public/api/user/tipoprojeto/`//首先,为了使用外部服务,您必须从http请求执行到要获取数据表单的端点

您的结束语:
http://localhost/WebServiceApp/public/api/user/tipoprojeto/

安装guzzle,它是一个php curl包装器,用于执行http调用。 在root dir中打开命令行并通过激发以下命令将guzzle注入到项目中:

composer require guzzlehttp/guzzle
确保通过添加

use GuzzleHttp\Client;
然后转到索引方法并执行以下操作:

public function index(){

// Create a client with a base URI
$client = new GuzzleHttp\Client(['base_uri' => 'http://localhost/WebServiceApp/public/api/user/tipoprojeto/']);

// Send a request to http://localhost/WebServiceApp/public/api/user/tipoprojeto/
$response = $client->request('GET', 'test');

// $response contains the data you are trying to get, you can do whatever u want with that data now. However to get the content add the line

$contents = $response->getBody()->getContents();

dd($contents);
}

$contents
包含数据,现在您可以做任何您想做的事。

路由::get('/',Painel\TipoProjetoController@All“);
您缺少斜杠。这不是问题,我的问题是索引()我的AppView项目控制器中的函数可以检索AppWs项目在其All方法中返回的数据在此处添加All方法…使用Guzzle。并正确定义您的路由。我只能通过Guzzle消费吗?好的,我将追随您的脚步,您认为我使用laravel中的web服务和应用程序是错误的吗仅使用laravel中的vision应用程序?您认为对于使用vision的应用程序,我应该只使用本机php或简单的html e jquery how requisitions ajax吗?如果您希望构建一个serverice api和一个客户端来使用ajax,那么您应该这样做。请问,我应该这样做吗?在我的web服务和我的视图中都使用laravel?
public function index(){

// Create a client with a base URI
$client = new GuzzleHttp\Client(['base_uri' => 'http://localhost/WebServiceApp/public/api/user/tipoprojeto/']);

// Send a request to http://localhost/WebServiceApp/public/api/user/tipoprojeto/
$response = $client->request('GET', 'test');

// $response contains the data you are trying to get, you can do whatever u want with that data now. However to get the content add the line

$contents = $response->getBody()->getContents();

dd($contents);
}