Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
100.00% |
1 / 1 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
11 / 11 |
| Answer | |
100.00% |
1 / 1 |
|
100.00% |
3 / 3 |
3 | |
100.00% |
11 / 11 |
| __construct | |
100.00% |
1 / 1 |
1 | |
100.00% |
9 / 9 |
|||
| question | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| customers | |
100.00% |
1 / 1 |
1 | |
100.00% |
1 / 1 |
|||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Models; |
| 4 | |
| 5 | use Illuminate\Database\Eloquent\Factories\HasFactory; |
| 6 | use Illuminate\Database\Eloquent\Model; |
| 7 | use Illuminate\Support\Str; |
| 8 | use Kwaadpepper\CrudPolicies\Enums\CrudAction; |
| 9 | use Kwaadpepper\CrudPolicies\Enums\CrudType; |
| 10 | use Kwaadpepper\CrudPolicies\Traits\IsCrudModel; |
| 11 | |
| 12 | class Answer extends Model |
| 13 | { |
| 14 | use HasFactory; |
| 15 | use IsCrudModel; |
| 16 | |
| 17 | /** @var string */ |
| 18 | protected $crudLabelColumn = 'answer'; |
| 19 | |
| 20 | /** @var string */ |
| 21 | protected $crudValueColumn = 'id'; |
| 22 | |
| 23 | /** |
| 24 | * The attributes that are mass assignable. |
| 25 | * |
| 26 | * @var string[] |
| 27 | */ |
| 28 | protected $fillable = [ |
| 29 | 'answer' |
| 30 | ]; |
| 31 | |
| 32 | /** |
| 33 | * Answer |
| 34 | * |
| 35 | * @param array $attributes |
| 36 | */ |
| 37 | public function __construct(array $attributes = []) |
| 38 | { |
| 39 | self::$editableProperties = [ |
| 40 | 'answer' => [ |
| 41 | 'label' => Str::ucfirst(trans('models.common.answer')), |
| 42 | 'type' => CrudType::string(), |
| 43 | 'validate' => [ |
| 44 | 'min:1', |
| 45 | 'max:255' |
| 46 | ], |
| 47 | 'actions' => [ |
| 48 | CrudAction::viewAny(), |
| 49 | CrudAction::view(), |
| 50 | CrudAction::create(), |
| 51 | CrudAction::update() |
| 52 | ] |
| 53 | ] |
| 54 | ]; |
| 55 | parent::__construct($attributes); |
| 56 | } |
| 57 | |
| 58 | // * RELATIONS |
| 59 | |
| 60 | /** |
| 61 | * Question BelongsTo relation |
| 62 | * |
| 63 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
| 64 | */ |
| 65 | public function question() |
| 66 | { |
| 67 | return $this->belongsTo(Question::class); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Answer belongsToMany relation |
| 72 | * |
| 73 | * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany |
| 74 | */ |
| 75 | public function customers() |
| 76 | { |
| 77 | return $this->belongsToMany(Customer::class, 'customer_answer'); |
| 78 | } |
| 79 | } |