File tree Expand file tree Collapse file tree 3 files changed +150
-3
lines changed
Expand file tree Collapse file tree 3 files changed +150
-3
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App \Models ;
4+
5+ use Illuminate \Database \Eloquent \Model ;
6+ use Illuminate \Support \Facades \Validator ;
7+
8+ class KeyMessage extends Model
9+ {
10+ /**
11+ * The database table used by the model.
12+ *
13+ * @var string
14+ */
15+ protected $ table = 'key_messages ' ;
16+
17+ /**
18+ * @var
19+ */
20+ protected $ errors ;
21+
22+ /**
23+ * @var bool
24+ */
25+ public $ timestamps = false ;
26+
27+ /**
28+ * The attributes that are mass assignable.
29+ *
30+ * @var array
31+ */
32+ protected $ fillable = ['entities_stage_id ' , 'title ' ];
33+
34+ /**
35+ * Model validation rules
36+ *
37+ * @var array
38+ */
39+ protected $ rules = [
40+ 'entities_stage_id ' => 'required|integer ' ,
41+ 'title ' => 'required|string|between:2,255 ' ,
42+ ];
43+
44+ public function validate ($ data )
45+ {
46+ $ v = Validator::make ($ data , $ this ->rules );
47+
48+ if ($ v ->fails ()) {
49+ $ this ->errors = $ v ->errors ();
50+
51+ return false ;
52+ }
53+
54+ return true ;
55+ }
56+
57+ /**
58+ * @return mixed
59+ */
60+ public function errors ()
61+ {
62+ return $ this ->errors ;
63+ }
64+
65+ public function entityStage ()
66+ {
67+ return $ this ->belongsTo (WhatnowEntityStage::class, 'entities_stage_id ' );
68+ }
69+
70+ public function supportingMessages ()
71+ {
72+ return $ this ->hasMany (SupportingMessage::class, 'key_message_id ' );
73+ }
74+ }
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace App \Models ;
4+
5+ use Illuminate \Database \Eloquent \Model ;
6+ use Illuminate \Support \Facades \Validator ;
7+
8+ class SupportingMessage extends Model
9+ {
10+ /**
11+ * The database table used by the model.
12+ *
13+ * @var string
14+ */
15+ protected $ table = 'supporting_messages ' ;
16+
17+ /**
18+ * @var
19+ */
20+ protected $ errors ;
21+
22+ /**
23+ * @var bool
24+ */
25+ public $ timestamps = false ;
26+
27+ /**
28+ * The attributes that are mass assignable.
29+ * @var array
30+ */
31+ protected $ fillable = ['key_message_id ' , 'content ' ];
32+
33+ /**
34+ * Model validation rules
35+ * @var array
36+ */
37+ protected $ rules = [
38+ 'key_message_id ' => 'required|integer ' ,
39+ 'content ' => 'required|string|between:2,1000 ' ,
40+ ];
41+
42+ /**
43+ * @param $data
44+ * @return bool
45+ */
46+ public function validate ($ data )
47+ {
48+ $ v = Validator::make ($ data , $ this ->rules );
49+
50+ if ($ v ->fails ()) {
51+ $ this ->errors = $ v ->errors ();
52+
53+ return false ;
54+ }
55+
56+ return true ;
57+ }
58+
59+ /**
60+ * @return mixed
61+ */
62+ public function errors ()
63+ {
64+ return $ this ->errors ;
65+ }
66+
67+ public function keyMessage ()
68+ {
69+ return $ this ->belongsTo (KeyMessage::class, 'key_message_id ' );
70+ }
71+ }
Original file line number Diff line number Diff line change @@ -32,7 +32,6 @@ class WhatNowEntityStage extends Model
3232 protected $ fillable = [
3333 'translation_id ' ,
3434 'language_code ' ,
35- 'urgency_id '
3635
3736 ];
3837
@@ -43,8 +42,6 @@ class WhatNowEntityStage extends Model
4342 */
4443 protected $ rules = [
4544 'language_code ' => 'required|string|between:2,10 ' ,
46- 'urgency_id ' => 'required|integer ' ,
47- 'content ' => 'string '
4845 ];
4946
5047 /**
@@ -76,4 +73,9 @@ public function translation()
7673 {
7774 return $ this ->belongsTo ('App\Models\WhatNowEntityTranslation ' , 'translation_id ' , 'id ' );
7875 }
76+
77+ public function keyMessages ()
78+ {
79+ return $ this ->hasMany (KeyMessage::class, 'entities_stage_id ' , 'id ' );
80+ }
7981}
You can’t perform that action at this time.
0 commit comments