Skip to content

Commit

Permalink
Merge pull request #2 from ibrahem-kamal/development
Browse files Browse the repository at this point in the history
remove views from the package and its service provider
  • Loading branch information
ibrahem-kamal authored Feb 5, 2024
2 parents d5f2d6a + da33fa1 commit c540ff9
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 3 deletions.
Empty file removed resources/views/.gitkeep
Empty file.
9 changes: 9 additions & 0 deletions src/Models/OtpCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,15 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\MorphTo;

/**
* Class OtpCode
*
* @property string $otp
* @property string $phone
* @property string $service
* @property \DateTime $expires_at
* @property \DateTime $verified_at
*/
class OtpCode extends Model
{
protected $fillable = ['otp', 'phone', 'service', 'expires_at', 'verified_at'];
Expand Down
6 changes: 4 additions & 2 deletions src/Otp.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Ibrahemkamal\Otp\Concerns\ServiceResponse;
use Ibrahemkamal\Otp\Contracts\HasOtp;
use Ibrahemkamal\Otp\Models\OtpCode;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;

class Otp
Expand Down Expand Up @@ -54,6 +53,7 @@ public function generate($otp = null): OtpCode
return $this->generate();
}

/** @phpstan-ignore-next-line */
return $this->model->otpCodes()->create([
'otp' => $otp,
'phone' => $this->getPhone(),
Expand Down Expand Up @@ -102,7 +102,7 @@ public function getPhone(): string
return $this->phone;
}

public function getModel(): ?Model
public function getModel(): ?HasOtp
{
return $this->model;
}
Expand Down Expand Up @@ -135,6 +135,7 @@ public function verifyOtp(string $otp): ServiceResponse
->whereNull('verified_at')
->first();
if ($otpCode) {
/** @phpstan-ignore-next-line */
if ($otpCode->expires_at->isPast()) {
return $this->serviceResponse->setSuccess(false)->setErrors(['otp' => __('OTP has expired')]);
}
Expand All @@ -143,6 +144,7 @@ public function verifyOtp(string $otp): ServiceResponse
} else {
$otpCode->update(['verified_at' => now()]);
}
/** @phpstan-ignore-next-line */
$otpCode->verified_at = now();

return $this->serviceResponse->setSuccess(true)->setData($otpCode);
Expand Down
1 change: 0 additions & 1 deletion src/OtpServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public function configurePackage(Package $package): void
$package
->name('laravel-otp')
->hasConfigFile()
->hasViews()
->hasMigration('create_laravel-otp_table')
->hasCommand(OtpPruneCommand::class);
}
Expand Down

0 comments on commit c540ff9

Please sign in to comment.