convenia/checklistable

使任何模型可检查,并为每个ID提供答案

v1.0.2 2018-05-11 18:01 UTC

This package is not auto-updated.

Last update: 2024-09-22 05:12:43 UTC


README

checklistable logo

               

Codacy Badge Codacy Badge Build Status GitHub forks Dependencies GitHub Issues Contributions welcome License

基本概述

在您的项目中添加与任何模型关联的清单

安装

composer require convenia/checklistable

发布迁移

php artisan vendor:publish --tag="checklistable"

迁移

php artisan migrate

用法

添加特性

namespace App\Model;

use Illuminate\Database\Eloquent\Model;
use Convenia\Checklistable\Traits\ChecklistableTrait;

class ModelClass extends Model
{
    use ChecklistableTrait;    

清单方法

checklist()
// Return ChecklistService Object
ModelClass::checklist($type, $ownerId);  
checklist()->get()
// Return Checklist Model, if not existe will create it
ModelClass::checklist($type, $ownerId)->get();  

问题方法

checklist()->questions()
// Return QuestionService Object
ModelClass::checklist($type, $ownerId)
    ->questions();  
checklist()->questions()->get()
// Return Collection of questions
ModelClass::checklist($type, $ownerId)
    ->questions()
        ->get();  
checklist()->questions()->fill()
// add and return question in lot (only if empty)
ModelClass::checklist($type, $ownerId)
    ->questions()
    ->fill([]);  
checklist()->questions()->delete()
// delete one question
ModelClass::checklist($type, $ownerId)
    ->questions()
    ->delete($questionId);  
checklist()->questions()->add()
// add one question an d return all
ModelClass::checklist($type, $ownerId)
    ->questions()
    ->add([
        'question' => 'What does Marcellus wallace looks like ?'
    ]);  

答案方法

checklist()->answer()
// Return QuestionService Object
ModelClass::checklist($type, $ownerId)
    ->answer();  
checklist()->answer()->get()
// retrive all answers about checklistable, if do not have, fill it
ModelClass::checklist($type, $ownerId)
    ->answer()
    ->get($checklistableId);  
checklist()->answer()->start()
// fill the answers with the questions
ModelClass::checklist($type, $ownerId)
    ->answer()
    ->start($checklistableId);  
checklist()->answer()->answer()
// change answer response
ModelClass::checklist($type, $ownerId)
    ->answer()
    ->start($checklistableId, $answerId, $answer = true)

许可证

Checklistable 是开源软件,许可协议为 MIT 许可证