Frequently asked questions crud implementation for laravel projects

Overview

Laravel FAQs

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

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

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

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

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

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

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

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

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

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.

<?php

namespace App\Http\Controllers;

use DetosphereLtd\LaravelFaqs\Actions\CreateFAQAction;

class FaqController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request, CreateFAQAction $action)
    {
        $action->execute([
            'question' => $request->question,
            'answer'=> $request->answer,
            'type' => $request->type
        ]);

        return response(201);
    }
}

Testing

vendor/bin/phpunit

Contributing

Please see CONTRIBUTING for details.

License

The MIT License (MIT). Please see License File for more information.

You might also like...
A collection of open source projects built using Laravel.

Open Laravel A repository of open source projects built using Laravel. Getting Started Clone the project repository by running the command below if yo

CRUD PHP, SQL PDO

PHP-Mastering CRUD em PHP usando MySQL PDO; Configure a ficheiro config.php de acordo com a sua configuração da base de dados PHP CRUD using PDO MySQL

 Learning about - Basic HTML & CSS, JSON, XML, Session & Cookies, CRUD Operations in Php using MySQL and Create MVC from scratch
Learning about - Basic HTML & CSS, JSON, XML, Session & Cookies, CRUD Operations in Php using MySQL and Create MVC from scratch

This Project is based on course CSC 3215. Learning about - Basic HTML & CSS, JSON, XML, Session & Cookies, CRUD Operations in Php using MySQL and Create MVC (Model–View–Controller) from scratch. Just learning about web technologies, Not focusing on UI (Bootstrap or other 3rd-Party UI libraries or frameworks).

Sistema web para empresa de diseño "Disema", con operaciones básicas CRUD y uso de html, JQ, JS, php y css

Disema System Sistema web para empresa de diseño "Disema", con operaciones básicas CRUD y uso de html, JQ, JS, php y css Para su correcto uso, deberá

CRUD  Build a system to insert student name information, grade the class name, and edit and delete this information
CRUD Build a system to insert student name information, grade the class name, and edit and delete this information

CRUD Build a system to insert student name information, grade the class name, and edit and delete this information

First SQL Project - HTML, Bootstrap, PHP enabling CRUD from web
First SQL Project - HTML, Bootstrap, PHP enabling CRUD from web

DB-Project First SQL Project with HTML, Bootstrap, PHP enabling CRUD from web Java for mocking data, enabling .csv input Idea This model corresponds t

API REST para CRUD de usuários

Crud de Usuários QUAL A FUNÇÃO DA API? Esta API tem como objetivo cadastrar usuários e seus respectivos endereços por meio de requests e também fazer

Easy to use utility functions for everyday PHP projects. This is a port of the Lodash JS library to PHP

Lodash-PHP Lodash-PHP is a port of the Lodash JS library to PHP. It is a set of easy to use utility functions for everyday PHP projects. Lodash-PHP tr

Use Ray in any PHP script without requiring it in your projects.

Global Ray Use Ray in any PHP script without requiring it in your projects. Require this package globally with Composer: composer global require cuyz/

Releases(1.0.2)
  • 1.0.2(Oct 14, 2021)

    • Added model documentation
    • Changed from fillable to guarded properties on the Faq model

    Full Changelog: https://github.com/Detosphere-Ltd/laravel-faqs/compare/1.0.1...1.0.2

    Source code(tar.gz)
    Source code(zip)
  • 1.0.1(Oct 12, 2021)

  • 1.0.0(Oct 12, 2021)

    Initial release of Laravel FAQs package

    • create faqs
    • update faqs
    • delete faqs
    • increment helpfulness of faq

    Full Changelog: https://github.com/Detosphere-Ltd/laravel-faqs/commits/1.0.0

    Source code(tar.gz)
    Source code(zip)
Owner
Detosphere Ltd
Detosphere Ltd
Cheatsheet for some Php knowledge you will frequently encounter in modern projects.

Cheatsheet for some Php knowledge you will frequently encounter in modern projects.

Arnaud Becher 1.1k Jan 2, 2023
This is an extension to my datacode interview questions.

This is an extension to my datacode interview questions. This is a fully working response form with email functionality as well as database manipulation.The form can be translated from French, English and Pirate based on the browser language.

null 1 Feb 13, 2022
Some exercises to practice whiteboard interview questions in PHP.

PHP Interview Exercises · A number of exercises to practice whiteboard interview questions in PHP. Inside exercises directory, you can find folders co

Anton Ždanov 421 Jan 9, 2023
Mega list of 1 on 1 meeting questions compiled from a variety to sources

Mega list of 1 on 1 meeting questions compiled from a variety to sources

Vidal Graupera 9.1k Dec 29, 2022
QuestionApp - a platform where users can ask questions and discuss about the subject they are curious about

QuestionApp About The Project It can be a trend according to the number of likes and comments that members can ask questions. ![Alt Text] Ask your any

Tolga Bayrak 4 Oct 7, 2022
Pheature flags toggle CRUD implementation

Pheature Flags Toggle CRUD Pheature flags toggle CRUD implementation Installation Describe package installation composer require pheature/toggle-crud

Pheature Flags 5 Dec 14, 2022
A helpful Laravel package to help me get started in Laravel projects quicker.

Launchpad A helpful Laravel package to help me get started in Laravel projects quicker. This is still a work in progress, so use at your own risk! CLI

Steve McDougall 13 Jun 15, 2023
Laravel 8 Roles + Permisos + CRUD + UI Stisla

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Informática DP 20 Dec 24, 2022
CRUD API em Laravel para registrar produtos.

CRUD API feito em laravel manipulando dados/registros de produtos. Criar um banco de dados chamado laravel_api utf8mb4_unicode_ci. Baixe o composer. P

Felipe Figueiredo 1 Mar 29, 2022
uses laravel breeze , CRUD, soft delete, Factories

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Roman Hossain Shaon 2 Sep 27, 2022