Skip to content

Commit

Permalink
WN-172, I've added the KeyMessage and SupportingMessage models with t…
Browse files Browse the repository at this point in the history
…heir respective relations.
  • Loading branch information
LDFOUR\luisd committed Feb 10, 2025
1 parent b2c5420 commit 93342ac
Show file tree
Hide file tree
Showing 3 changed files with 150 additions and 3 deletions.
74 changes: 74 additions & 0 deletions app/Models/KeyMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Validator;

class KeyMessage extends Model
{
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'key_messages';

/**
* @var
*/
protected $errors;

/**
* @var bool
*/
public $timestamps = false;

/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = ['entities_stage_id', 'title'];

/**
* Model validation rules
*
* @var array
*/
protected $rules = [
'entities_stage_id' => 'required|integer',
'title' => 'required|string|between:2,255',
];

public function validate($data)
{
$v = Validator::make($data, $this->rules);

if ($v->fails()) {
$this->errors = $v->errors();

return false;
}

return true;
}

/**
* @return mixed
*/
public function errors()
{
return $this->errors;
}

public function entityStage()
{
return $this->belongsTo(WhatnowEntityStage::class, 'entities_stage_id');
}

public function supportingMessages()
{
return $this->hasMany(SupportingMessage::class, 'key_message_id');
}
}
71 changes: 71 additions & 0 deletions app/Models/SupportingMessage.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Validator;

class SupportingMessage extends Model
{
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'supporting_messages';

/**
* @var
*/
protected $errors;

/**
* @var bool
*/
public $timestamps = false;

/**
* The attributes that are mass assignable.
* @var array
*/
protected $fillable = ['key_message_id', 'content'];

/**
* Model validation rules
* @var array
*/
protected $rules = [
'key_message_id' => 'required|integer',
'content' => 'required|string|between:2,1000',
];

/**
* @param $data
* @return bool
*/
public function validate($data)
{
$v = Validator::make($data, $this->rules);

if ($v->fails()) {
$this->errors = $v->errors();

return false;
}

return true;
}

/**
* @return mixed
*/
public function errors()
{
return $this->errors;
}

public function keyMessage()
{
return $this->belongsTo(KeyMessage::class, 'key_message_id');
}
}
8 changes: 5 additions & 3 deletions app/Models/WhatNowEntityStage.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ class WhatNowEntityStage extends Model
protected $fillable = [
'translation_id',
'language_code',
'urgency_id'

];

Expand All @@ -43,8 +42,6 @@ class WhatNowEntityStage extends Model
*/
protected $rules = [
'language_code' => 'required|string|between:2,10',
'urgency_id' => 'required|integer',
'content' => 'string'
];

/**
Expand Down Expand Up @@ -76,4 +73,9 @@ public function translation()
{
return $this->belongsTo('App\Models\WhatNowEntityTranslation', 'translation_id', 'id');
}

public function keyMessages()
{
return $this->hasMany(KeyMessage::class, 'entities_stage_id', 'id');
}
}

0 comments on commit 93342ac

Please sign in to comment.