PHPackages                             bluecloud/laravel-security-question - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Authentication &amp; Authorization](/categories/authentication)
4. /
5. bluecloud/laravel-security-question

ActiveLibrary[Authentication &amp; Authorization](/categories/authentication)

bluecloud/laravel-security-question
===================================

Helpers for managing security questions within your Laravel project

v1.0.0(2y ago)1353MITPHPPHP ^7.4|^8.0

Since Aug 22Pushed 2y ago1 watchersCompare

[ Source](https://github.com/ykalinde/laravel-security-question)[ Packagist](https://packagist.org/packages/bluecloud/laravel-security-question)[ RSS](/packages/bluecloud-laravel-security-question/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (1)Versions (2)Used By (0)

Introduction
------------

[](#introduction)

Laravel security questions helps you easily integration security question facility for your project

Installation
------------

[](#installation)

```
composer require bluecloud/laravel-security-question

```

Migrate Tables
--------------

[](#migrate-tables)

Run the following command to create tables to enable saving security questions

```
php artisan migrate

```

Publish Config
--------------

[](#publish-config)

The package allows you to publish a config file to change settings for the package. Run the command below and select `Bluecloud\SecurityQuestionHelpers\SecurityQuestionHelpersProvider`. A configuration file will be created at `config/questions.php`

```
php artisan vendor:publish

```

Load Questions
--------------

[](#load-questions)

Run the following command

```
php artisan questions:migrate

```

Adding Trait to User
--------------------

[](#adding-trait-to-user)

Add the `HasSecurityQuestions` trait to your `App\Models\User` model as indicated below.

```
use Bluecloud\SecurityQuestionHelpers\HasSecurityQuestions;

class User extends Authenticatable
{
    use HasApiTokens, HasFactory, Notifiable, HasSecurityQuestions;
}
```

Add Question(s) for User
------------------------

[](#add-questions-for-user)

To add question(s) for a user, add the code below

```
$user = auth()->user();
$user->save_questions([
    ["security_question_id" => 1, "answer" => "Blantyre, Malawi"]
]);
```

Checking Question Answer
------------------------

[](#checking-question-answer)

To check a user's submitted answer against the saved answers, add the code below

```
 $question = SecurityQuestion::find(1);
 $check = $user->check_answer($question, "Blantyre, Malawi");
```

**Note**: The questions will **sync**. If the question was already attached for the user, the new answer will update the existing record

Routes
------

[](#routes)

To manage question, you can make use of preconfigured api endpoints

### 1. List Security Question

[](#1-list-security-question)

```
GET /security-questions

```

### 2. Create Security Question

[](#2-create-security-question)

```
POST /security-questions

{
    "name": "Sample security question"
}

```

### 3. Delete Security Question

[](#3-delete-security-question)

```
DELETE /security-question/{id}

```

Configuration
-------------

[](#configuration)

Change package settings

### 1. Default Questions

[](#1-default-questions)

Navigate to `config/questions.php` and find default security questions. You may change if you please.

```
