jawabapp/cloud-messaging


README

安装

您可以通过 composer 安装此包

composer require jawabapp/cloud-messaging

使用方法

User.php 模型
use Jawabapp\CloudMessaging\Contracts\TargetAudience;
use Jawabapp\CloudMessaging\Traits\EloquentGetTableNameTrait;
use Jawabapp\CloudMessaging\Traits\HasTargetAudience;

class User extends Authenticatable implements TargetAudience
{
	use HasTargetAudience;
	use EloquentGetTableNameTrait;
	//...
}

实现 TargetAudience 接口中的那些方法。

use Illuminate\Database\Eloquent\Builder;

class User extends Authenticatable implements TargetAudience
{
	public static function targetAudienceForPhoneNumbers(Builder $query, $phone_numbers)
    {
        //...
    }

	public static function targetAudienceForOS(Builder $query, $os)
    {
        //...
    }
}
添加更多过滤器
User.php 模型
public static function targetAudienceForCountries(Builder $query, $condition, $options, &$joins)
    {
        if ($condition === 'is_not_in') {
            $query->whereNotIn('phone_country', $options);
        } else {
            $query->whereIn('phone_country', $options);
        }
    }
cloud-messaging.php 配置文件
'filter_types' => [
	[
            'value' => 'countries',
            'label' => 'Country/Region',
            'selectLabel' => 'Countries',
            'conditions' => [
                [
                    'value' => 'is_in',
                    'label' => 'Is in',
                ],
                [
                    'value' => 'is_not_in',
                    'label' => 'Is not in',
                ]
            ]
	],
	//...
]
web.php 网络路由文件
Route::group(['prefix' => env('JAWAB_CLOUD_MESSAGING_PATH', 'jawab-notifications')], function () {
    Route::group(['prefix' => 'api'], function () {
        Route::get('countries', 'Api\Admin\CountryController@index');
        //...
    });
});
CountryController.php 网络路由文件
public function index(Request $request)
{

    $mobile_os = $request->get('os');

    return User::select(['phone_country_code'])
        ->distinct()
        ->whereNotNull('phone_country_code')
        ->where('os', $mobile_os)
        ->get()
        ->map(function ($item) {
            return [
                'value' => $item->phone_country_code,
                'text' => $item->phone_country_code,
            ];
        });
}
更改 notifilable 模型
cloud-messaging.php 配置文件
[
	'notifiable_model' => \App\Models\User::class,
]

变更日志

有关最近更改的更多信息,请参阅 变更日志

贡献

有关详细信息,请参阅 贡献指南

安全

如果您发现任何与安全相关的问题,请通过电子邮件 trmdy@hotmail.com 而不是使用问题跟踪器。

鸣谢

许可证

MIT 许可证 (MIT)。有关更多信息,请参阅 许可证文件