PHPackages                             lyxxxh/larapi - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. lyxxxh/larapi

ActiveLibrary[API Development](/categories/api)

lyxxxh/larapi
=============

laravel调用其他路由 获取返回数据

09PHP

Since Aug 10Pushed 6y ago1 watchersCompare

[ Source](https://github.com/lyxxg/larapi)[ Packagist](https://packagist.org/packages/lyxxxh/larapi)[ RSS](/packages/lyxxxh-larapi/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

### 安装

[](#安装)

composer require lyxxxh/larapi

注册`\Xxh\LarApi\LarApiMiddleWare`中间件

```
 /*App\Http\Kernel.php*/
 protected $middlewareGroups = [
         'web' => [
             ..............,
             \Xxh\LarApi\LarApiMiddleWare::class
         ]
```

### 使用

[](#使用)

例如写好了轮播图接口

```
Route::get('article/{id}', function ($id) {
        return '你访问id='.$id.'的文章';
});
Route::get('banner',function(){
    return ['banner/1.png','banner/2.png','banner/3.png'];
});

在blade模板里
{{ $api->get('article/4') }}

@foreach($api->getc('banner') as $img)

@endforeach

```

### get()与getc()区别

[](#get与getc区别)

```
   getc() 有缓存则返回缓存，没有则调用get() 缓存数据再返回。
   get()  调用路由返回数据

```

### 自定义

[](#自定义)

新建中间件并注册。LarApiService是traits

```
   use \Xxh\LarApi\LarApiService;
   public function handle($request, Closure $next)
   {
       view()->share('api',$this);
       return $next($request);
   }

   public function get()
   {
       dd("重写get方法");
   }

   public function gete()
   {
       dd("扩展一个方法");
   }

```

### 作用

[](#作用)

由于是api,可以与其他的平台通用数据。

适用于小规模网站前后分离; 如果采用单页，seo将会是个麻烦的问题;

### 只有get请求

[](#只有get请求)

需要提交表单，使用form表单 或者 ajax方式提交吧。

###  Health Score

18

—

LowBetter than 8% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community4

Small or concentrated contributor base

Maturity36

Early-stage or recently created project

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/0fbda2846ce7576ecbef245263ab795e62a1ea4a31c6d58bfdea89e20194ec90?d=identicon)[lyxxg](/maintainers/lyxxg)

### Embed Badge

![Health badge](/badges/lyxxxh-larapi/health.svg)

```
[![Health](https://phpackages.com/badges/lyxxxh-larapi/health.svg)](https://phpackages.com/packages/lyxxxh-larapi)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
