-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
WN-172, I've added the KeyMessage and SupportingMessage models with t…
…heir respective relations.
- Loading branch information
LDFOUR\luisd
committed
Feb 10, 2025
1 parent
b2c5420
commit 93342ac
Showing
3 changed files
with
150 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters