PHP code example of jawabapp / cloud-messaging

1. Go to this page and download the library: Download jawabapp/cloud-messaging library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

jawabapp / cloud-messaging example snippets


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;
	//...
}


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)
    {
        //...
    }
}

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);
        }
    }

'filter_types' => [
	[
            'value' => 'countries',
            'label' => 'Country/Region',
            'selectLabel' => 'Countries',
            'conditions' => [
                [
                    'value' => 'is_in',
                    'label' => 'Is in',
                ],
                [
                    'value' => 'is_not_in',
                    'label' => 'Is not in',
                ]
            ]
	],
	//...
]

Route::group(['prefix' => env('JAWAB_CLOUD_MESSAGING_PATH', 'jawab-notifications')], function () {
    Route::group(['prefix' => 'api'], function () {
        Route::get('countries', 'Api\Admin\CountryController@index');
        //...
    });
});

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,
            ];
        });
}

[
	'notifiable_model' => \App\Models\User::class,
]