PHPackages                             lruisen/inertia-think - 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. [Framework](/categories/framework)
4. /
5. lruisen/inertia-think

ActiveLibrary[Framework](/categories/framework)

lruisen/inertia-think
=====================

The ThinkPHP adapter for Inertia.js.

v1.0.1(1y ago)310MITPHPPHP ^8.1

Since Jun 14Pushed 1y ago1 watchersCompare

[ Source](https://github.com/lruisen/inertia-think)[ Packagist](https://packagist.org/packages/lruisen/inertia-think)[ RSS](/packages/lruisen-inertia-think/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependencies (7)Versions (3)Used By (0)

inertia-think
=============

[](#inertia-think)

Inertia.js的ThinkPHP适配器（ThinkPHP 8）

访问[inertiajs.com](https://inertiajs.com/)了解更多信息。

### 安装依赖项

[](#安装依赖项)

首先，使用Composer包管理器安装Inertia服务器端适配器。

```
composer require lruisen/inertia-think

```

### 根模板

[](#根模板)

接下来，设置将在访问应用程序的第一个页面时加载的根模板。这将用于加载您的网站资源（CSS和JavaScript），还将包含一个根＜div＞，用于启动您的JavaScript应用程序。

```
>

```

默认情况下，Inertia的ThinkPHP适配器将假定您的根模板名为`app.html`。如果您想使用不同的根视图，可以使用`Inertia::setRootView()`方法进行更改。

### 中间件

[](#中间件)

::: warning

将`Inertia\InertiaResponseMiddleware` 中间件加入到`app/middleware.php`文件中或您的指定应用中间件配置文件中。

:::

接下来，我们需要创建Inertia中间件。您可以通过以下command命令来完成将`HandleInertiaRequests`中间件发布到您的应用程序。

```
php think inertia:middleware
```

中间件发布后：

- 如果是单应用，将`HandleInertiaRequests`中间件附加到`app/middleware.php`文件中。
- 如果是多应用，将`HandleInertiaRequests`中间件添加到对应应用的`middleware.php`文件中。

### 创建响应

[](#创建响应)

就这样，服务端配置基本完成！现在，您可以开始创建Inertia页面并通过响应进行渲染了。

```
use Inertia\facade\Inertia;

class EventsController extends Controller
{
    public function show(Event $event)
    {
        return Inertia::render('Event/Show', [
            'event' => $event->only(
                'id',
                'title',
                'start_date',
                'description'
            ),
        ]);
    }
}
```

### 关于路由

[](#关于路由)

如果您的页面不需要相应的控制器方法，如“FAQ”或“about”页面，则可以通过`InertiaRoute::inertia()`方法或使用闭包形式直接路由到组件。

```
use Inertia\Facade\InertiaRoute;
use think\facade\Route;

InertiaRoute::inertia('/about','about');

# 或

Route::get('/about',fn () => inertia('about'));
```

###  Health Score

27

—

LowBetter than 49% of packages

Maintenance33

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

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.

###  Release Activity

Cadence

Every ~17 days

Total

2

Last Release

680d ago

PHP version history (2 changes)v1.0.0PHP ^8.0

v1.0.1PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/e9d171e46e8cc64625d6b62966225bb7471311b79043aae2737e662c01781b7d?d=identicon)[lruisen](/maintainers/lruisen)

---

Top Contributors

[![lruisen](https://avatars.githubusercontent.com/u/171680804?v=4)](https://github.com/lruisen "lruisen (6 commits)")

---

Tags

inertiathinkphp

### Embed Badge

![Health badge](/badges/lruisen-inertia-think/health.svg)

```
[![Health](https://phpackages.com/badges/lruisen-inertia-think/health.svg)](https://phpackages.com/packages/lruisen-inertia-think)
```

###  Alternatives

[laravel/framework

The Laravel Framework.

34.6k509.9M17.0k](/packages/laravel-framework)[shopware/platform

The Shopware e-commerce core

3.3k1.5M3](/packages/shopware-platform)[laravel/dusk

Laravel Dusk provides simple end-to-end testing and browser automation.

1.9k36.7M259](/packages/laravel-dusk)[drupal/core

Drupal is an open source content management platform powering millions of websites and applications.

19462.3M1.3k](/packages/drupal-core)[drupal/core-recommended

Locked core dependencies; require this project INSTEAD OF drupal/core.

6939.5M343](/packages/drupal-core-recommended)[magento/community-edition

Magento 2 (Open Source)

12.1k52.1k10](/packages/magento-community-edition)

PHPackages © 2026

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