PHPackages                             detosphere-ltd/laravel-faqs - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. detosphere-ltd/laravel-faqs

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

detosphere-ltd/laravel-faqs
===========================

Frequently asked questions crud implementation

1.0.2(4y ago)320MITPHPPHP ^7.3|^8.0

Since Oct 12Pushed 4y ago2 watchersCompare

[ Source](https://github.com/Detosphere-Ltd/laravel-faqs)[ Packagist](https://packagist.org/packages/detosphere-ltd/laravel-faqs)[ RSS](/packages/detosphere-ltd-laravel-faqs/feed)WikiDiscussions main Synced yesterday

READMEChangelog (3)Dependencies (7)Versions (4)Used By (0)

Laravel FAQs
============

[](#laravel-faqs)

This is a simple package to help manage frequently asked questions in a project.

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

[](#installation)

You can install the package via composer by running:

```
composer require detosphere-ltd/laravel-faqs
```

After the installation has completed, the package will automatically register itself. Run the following to publish the migration file

```
php artisan vendor:publish --provider="DetosphereLtd\LaravelFaqs\FAQServiceProvider"
```

After publishing the migration you can create the faqs table by running the migrations:

```
php artisan migrate
```

Models and Migrations
---------------------

[](#models-and-migrations)

This package has only one model (`Faq`) and its corresponding migration file. You are allowed to extend it and use it any how you want. The model only guarded properties on the model are the `id` and `uuid`.

### Scopes

[](#scopes)

The Faq model has `scopeType` to query faqs by type. It is as easy as shown below.

```
$faqs = \DetosphereLtd\LaravelFaqs\Models\Faq::type('type')->get();
```

Action classes
--------------

[](#action-classes)

This package exposes four action classes. Find details about them below.

### CreateFAQAction

[](#createfaqaction)

This is used to create a new faq. The execute method accepts an array. It returns the created faq.

```
$faq = (new CreateFAQAction)->execute([
    'question' => 'What does your app do?',
    'answer' => 'It helps manage Frequently asked questions on any application.',
    'type' => 'type'
]);
```

### UpdateFAQAction

[](#updatefaqaction)

This is used to update an already existing faq. The execute method accepts the faq to update and an array. It returns the updated faq.

```
$faq = \DetosphereLtd\LaravelFaqs\Models\Faq::first();

$updatedFaq = (new UpdateFAQAction)->execute($faq, [
    'question' => 'What does your app do?',
    'answer' => 'It helps manage Frequently asked questions on any application.',
    'type' => 'type'
]);
```

### DeleteFAQAction

[](#deletefaqaction)

This is used to delete an existing faq from the database. The execute method accepts the faq to delete. Faqs are soft deleted. It returns void.

```
$faq = \DetosphereLtd\LaravelFaqs\Models\Faq::first();

(new DeleteFAQAction)->execute($faq);
```

### IncrementFAQHelpfulnessAction

[](#incrementfaqhelpfulnessaction)

This is used to increment the `helpful_yes` and `helpful_no` of an existing faq in the database. The execute method accepts the faq to increment and the helpfulness to increment. Helpful must be `yes` or `no`. It returns the incremented faq. Throws an query exception if invalid `helpful` paramater is passed.

```
$faq = \DetosphereLtd\LaravelFaqs\Models\Faq::first();

$incrementedYes = (new IncrementFAQHelpfulnessAction)->execute($faq, 'yes');

$incrementedNo = (new IncrementFAQHelpfulnessAction)->execute($faq, 'no');
```

Usage
-----

[](#usage)

You can instantiate the class like you would any normal PHP class

```
(new CreateFAQAction)->execute([
    'question' => 'What does your app do?',
    'answer' => 'It helps manage Frequently asked questions on any application.',
    'type' => 'type'
]);
```

Also, you can also resolve the class from laravel's container

```
app(CreateFAQAction::class)->execute([
   'question' => 'What does your app do?',
    'answer' => 'It helps manage Frequently asked questions on any application.',
    'type' => 'type'
]);
```

Lastly, you can also inject the action class into your controller method like below.

```
