File tree Expand file tree Collapse file tree 1 file changed +40
-1
lines changed
Expand file tree Collapse file tree 1 file changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ class Resource extends Model
2222 * @var array
2323 */
2424 protected $ fillable = ['name ' , 'use_id ' ];
25-
25+
2626 /**
2727 * define the one-to-many relationship between a resource and its contents
2828 * @return \Illuminate\Database\Eloquent\Relations\HasMany the relationship accessor
@@ -72,4 +72,43 @@ public function class()
7272 {
7373 return $ this ->belongsTo (Academic_Class::class, 'class_id ' );
7474 }
75+
76+ /**
77+ * Is this resource viewable by the public?
78+ * @return boolean
79+ */
80+ public function status ()
81+ {
82+ return boolval ($ this ->status );
83+ }
84+
85+ /**
86+ * Get the indexable data array for the model.
87+ * @return array
88+ */
89+ public function toSearchableArray ()
90+ {
91+ $ resource = collect ();
92+ $ resource ['name ' ] = $ this ->name ;
93+ $ resource ['author ' ] = $ this ->author ->name ();
94+ $ resource ['use ' ] = $ this ->use ->name ;
95+ $ resource ['class ' ] = $ this ->class ->name ;
96+ $ resource ['contents ' ] = $ this ->contents ->map (
97+ function ($ content )
98+ {
99+ $ new_content = collect ($ content );
100+ return $ new_content ->only (['name ' , 'type ' , 'content ' ]);
101+ }
102+ )->toArray ();
103+ return $ resource ->toArray ();
104+ }
105+
106+ /**
107+ * Should this resource be searchable?
108+ * @return boolean
109+ */
110+ public function shouldBeSearchable ()
111+ {
112+ return $ this ->status ();
113+ }
75114}
You can’t perform that action at this time.
0 commit comments