Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
orkhanshukurlu committed Apr 16, 2023
0 parents commit 811d873
Show file tree
Hide file tree
Showing 11 changed files with 564 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) Orkhan Shukurlu <[email protected]>

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
91 changes: 91 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
<img src="https://banners.beyondco.de/Laravel%20MSM.png?theme=light&packageManager=composer+require&packageName=orkhanshukurlu%2Flaravel-msm&pattern=brickWall&style=style_1&description=Send+SMS+with+MSM&md=1&showWatermark=0&fontSize=100px&images=https%3A%2F%2Flaravel.com%2Fimg%2Flogomark.min.svg">

Laravel MSM - MSM provayderi vasitəsilə SMS göndərilməsini təmin edən Laravel paketidir

[![Laravel 10](https://img.shields.io/badge/Laravel-10-red.svg)](http://laravel.com)
[![Latest Stable Version](https://img.shields.io/packagist/v/orkhanshukurlu/laravel-msm.svg)](https://packagist.org/packages/orkhanshukurlu/laravel-msm)
[![Total Downloads](https://poser.pugx.org/orkhanshukurlu/laravel-msm/downloads.png)](https://packagist.org/packages/orkhanshukurlu/laravel-msm)
[![License](http://poser.pugx.org/orkhanshukurlu/laravel-msm/license)](https://packagist.org/packages/orkhanshukurlu/laravel-msm)


## Quraşdırma

`composer` vasitəsilə paketi quraşdırın

composer require orkhanshukurlu/laravel-msm

`config``migration` faylını kopyalayın

php artisan vendor:publish --provider="OrkhanShukurlu\MSM\MSMServiceProvider"

`migration` fayllarını işə salın

php artisan migrate

## Konfiqurasiya

`.env` faylına aşağıdakı konfiqurasiyaları əlavə edin

```php
MSM_USERNAME=
MSM_PASSWORD=
MSM_SENDER=
MSM_LOGGING=
```

- `MSM_USERNAME` - MSM tərəfindən verilən istifadəçi adını əlavə edin
- `MSM_PASSWORD` - MSM tərəfindən verilən şifrəni əlavə edin
- `MSM_SENDER` - MSM tərəfindən verilən göndərən adını əlavə edin
- `MSM_LOGGING` - Hər SMS sorğusunun cədvələ əlavə olunmasını istəyirsinizsə `true` edin

## İstifadə

`send` metodunu istifadə edərək telefon nömrəsinə SMS göndərin

```php

MSM::send('+994773339800', 'Hello world !');

// və ya

msm()->send('+994773339800', 'Hello world !');

```

`try-catch` blokunu istifadə edərək mümkün xətaları idarə edin

```php

try {
MSM::send('+994773339800', 'Hello world !');

// SMS uğurla göndərildi

} catch (SMSNotSentException $exception) {
Log::error($exception->getMessage());

// SMS göndərilərkən xəta baş verdi
}

```
### Loglama

Loglama aktiv olduqda hər SMS sorğusu üçün `msm_logs` cədvəlinə məlumat əlavə olunacaq

> Hər hansısa nömrəyə göndərilən bütün SMS sorğuları haqqında məlumat əldə etmək üçün `getByPhone` metodundan istifadə edə bilərsiniz
```php

MSMLog::getByPhone('+994773339800');

```

> Göndərilən bütün SMS sorğuları daha ətraflı məlumat əldə etmək üçün `MSMLog` modelindən istifadə edə bilərsiniz
### Lisenziya

Laravel MSM [MIT lisenziyası](https://github.com/orkhanshukurlu/laravel-msm/blob/master/LICENSE.md) altında buraxılıb

### Əlaqə

Linkedin: [Orxan Şükürlü](https://www.linkedin.com/in/orkhansh/)
45 changes: 45 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "orkhanshukurlu/laravel-msm",
"description": "A package written for sending SMS with MSM provider in Laravel",
"keywords": [
"orkhanshukurlu",
"laravel",
"msm",
"sms"
],
"homepage": "https://github.com/orkhanshukurlu/laravel-msm",
"license": "MIT",
"authors": [
{
"name": "Orkhan Shukurlu",
"email": "[email protected]",
"role": "Developer"
}
],
"require": {
"php": "^8.1",
"illuminate/container": "^10.0",
"illuminate/database": "^10.0",
"illuminate/support": "^10.0"
},
"autoload": {
"psr-4": {
"OrkhanShukurlu\\MSM\\": "src/"
},
"files": [
"src/helpers.php"
]
},
"extra": {
"laravel": {
"providers": [
"OrkhanShukurlu\\MSM\\MSMServiceProvider"
]
}
},
"config": {
"sort-packages": true
},
"minimum-stability": "dev",
"prefer-stable": true
}
28 changes: 28 additions & 0 deletions config/msm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

return [

/*
* Username provided by MSM.
*/

'username' => env('MSM_USERNAME'),

/*
* Password provided by MSM.
*/

'password' => env('MSM_PASSWORD'),

/*
* Sender name provided by MSM.
*/

'sender' => env('MSM_SENDER'),

/*
* Enable or disable database SMS logging mode.
*/

'logging' => env('MSM_LOGGING', false),
];
31 changes: 31 additions & 0 deletions database/migrations/create_msm_logs_table.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('msm_logs', function (Blueprint $table) {
$table->id();
$table->string('phone');
$table->string('message');
$table->integer('response_code')->nullable();
$table->string('response_text')->nullable();
$table->timestamp('sent_at')->useCurrent();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('msm_logs');
}
};
11 changes: 11 additions & 0 deletions src/Exceptions/SMSNotSentException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace OrkhanShukurlu\MSM\Exceptions;

use Exception;

final class SMSNotSentException extends Exception
{
}
25 changes: 25 additions & 0 deletions src/Facades/MSM.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php

declare(strict_types=1);

namespace OrkhanShukurlu\MSM\Facades;

use Illuminate\Support\Facades\Facade;

/**
* @method static void send(int|string $phone, int|string $message)
*
* @see \OrkhanShukurlu\MSM\SendSMS
*/
final class MSM extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor(): string
{
return \OrkhanShukurlu\MSM\SendSMS::class;
}
}
49 changes: 49 additions & 0 deletions src/MSMServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

declare(strict_types=1);

namespace OrkhanShukurlu\MSM;

use Illuminate\Support\ServiceProvider;
use OrkhanShukurlu\MSM\Facades\MSM;

final class MSMServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot(): void
{
if (file_exists($file = __DIR__ . '/helpers.php')) {
require_once $file;
}

if (! $this->app->runningInConsole()) {
return;
}

$this->publishes([
__DIR__ . '/../config/msm.php' => config_path('msm.php'),
], 'msm-config');

$this->publishes([
__DIR__ . '/../database/migrations/create_msm_logs_table.php' => $this->app->databasePath('migrations/' . date('Y_m_d_His') . '_create_msm_logs_table.php'),
], 'msm-migrations');
}

/**
* Register the service provider.
*
* @return void
*/
public function register(): void
{
$this->mergeConfigFrom(__DIR__ . '/../config/msm.php', 'msm');

$this->app->singleton('msm', function (): MSM {
return new MSM();
});
}
}
60 changes: 60 additions & 0 deletions src/Models/MSMLog.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<?php

declare(strict_types=1);

namespace OrkhanShukurlu\MSM\Models;

use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Model;

final class MSMLog extends Model
{
/**
* Indicates if the model should be timestamped.
*
* @var bool
*/
public $timestamps = false;

/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'sent_at' => 'datetime',
];

/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'phone',
'message',
'response_code',
'response_text',
];

/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'msm_logs';

/**
* Get all log data by the phone number.
*
* @param int|string $phone
*
* @return Collection
*/
public static function getByPhone(int|string $phone): Collection
{
return self::query()
->where('phone', $phone)
->get();
}
}
Loading

0 comments on commit 811d873

Please sign in to comment.