定制 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.

detosphere-ltd/laravel-faqs 适用场景与选型建议

detosphere-ltd/laravel-faqs 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 20 次下载、GitHub Stars 达 3, 最近一次更新时间为 2021 年 10 月 12 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「faqs」 「frequently-asked-questions」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 detosphere-ltd/laravel-faqs 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 detosphere-ltd/laravel-faqs 我们能提供哪些服务?
定制开发 / 二次开发

基于 detosphere-ltd/laravel-faqs 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

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