Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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');
}
}
7 changes: 5 additions & 2 deletions app/Models/WhatNowEntityStage.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ class WhatNowEntityStage extends Model
'translation_id',
'language_code',
'stage',
'content'
];

/**
Expand All @@ -54,7 +53,6 @@ class WhatNowEntityStage extends Model
protected $rules = [
'language_code' => 'required|string|between:2,10',
'stage' => 'string|max:10',
'content' => 'string'
];

/**
Expand Down Expand Up @@ -86,5 +84,10 @@ public function translation()
{
return $this->belongsTo('App\Models\WhatNowEntityTranslation', 'translation_id', 'id');
}

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

Loading