定制 detosphere-ltd/laravel-faqs 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

detosphere-ltd/laravel-faqs

Composer 安装命令:

composer require detosphere-ltd/laravel-faqs

包简介

Frequently asked questions crud implementation

README 文档

README

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.

统计信息

  • 总下载量: 20
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 3
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 3
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2021-10-12

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固