lighth7015 / laravel-appwrite
一个用于AppWrite的Laravel包,使用AppWrite PHP SDK
Requires
- php: ^7.4 || ^8.0
- appwrite/appwrite: ^6.0
- illuminate/contracts: ^8.0 || ^9.0
- illuminate/support: ^8.0 || ^9.0
- symfony/cache: ^5.4 || ^6.0
Requires (Dev)
- orchestra/testbench: ^6.0 || 7.0
- symplify/easy-coding-standard: ^10.0
This package is auto-updated.
Last update: 2024-09-19 12:07:07 UTC
README
一个用于Firebase PHP Admin SDK的Laravel包。
安装
此包需要Laravel 8.x及更高版本或Lumen 8.x及更高版本。
composer require lighth7015/laravel-appwrite
如果您使用Lumen或未使用Laravel的包自动发现,请在config/app.php
(Laravel)或bootstrap/app.php
(Lumen)中添加以下服务提供者
Laravel
<?php // config/app.php return [ // ... 'providers' => [ // ... Kreait\Laravel\Firebase\ServiceProvider::class ] // ... ];
Lumen
<?php // bootstrap/app.php $app->register(Kreait\Laravel\Firebase\ServiceProvider::class); // If you want to use the Facades provided by the package $app->withFacades();
配置
为了使用服务器SDK访问Firebase项目和其相关服务,请求必须进行认证。对于服务器之间的通信,这是通过服务账户完成的。
此包使用自动发现来查找默认项目所需的凭据,以通过检查某些环境变量并查看Google的已知路径来认证请求到Firebase API。
如果您尚未生成服务账户,可以按照官方文档页面上的说明操作https://firebase.google.com/docs/admin/setup#initialize_the_sdk。
一旦下载了服务账户JSON文件,您可以通过在.env
文件中指定以FIREBASE_
开头的环境变量来配置此包。通常,以下内容对于包的正常工作是必需的
# relative or full path to the Service Account JSON file
FIREBASE_CREDENTIALS=
# You can find the database URL for your project at
# https://console.firebase.google.com/project/_/database
FIREBASE_DATABASE_URL=https://<your-project>.firebaseio.com
有关进一步配置的详细信息,请参阅config/firebase.php。您可以通过将其复制到您的本地config
目录或通过定义配置文件中使用的环境变量来修改配置
# Laravel php artisan vendor:publish --provider="Kreait\Laravel\Firebase\ServiceProvider" --tag=config # Lumen mkdir -p config cp vendor/lighth7015/laravel-appwrite/config/firebase.php config/firebase.php
使用
一旦检索到组件,请参阅Firebase PHP Admin SDK的文档以获取有关如何使用的更多信息。
您不需要也不应该使用SDK文档中描述的new Factory()
模式,这已经通过Laravel服务提供者为您完成。请使用依赖注入、门面或app()
助手代替
多个项目
可以通过在config/firebase.php
中的项目数组中添加另一个部分来在config/firebase.php中配置多个项目。
在访问组件时,门面使用默认项目。您也可以显式使用一个项目
use Kreait\Laravel\Firebase\Facades\Firebase; // Return an instance of the Auth component for the default Firebase project $defaultAuth = Firebase::auth(); // Return an instance of the Auth component for a specific Firebase project $appAuth = Firebase::project('app')->auth(); $anotherAppAuth = Firebase::project('another-app')->auth();
支持
如果您或您的团队依赖于此项目以及维护它,请考虑成为赞助商 🙏。更高的层级可以提供扩展支持。
许可证
Firebase Admin PHP SDK是在MIT许可证下授权的。
您对Firebase的使用受Firebase服务条款的约束。