File tree Expand file tree Collapse file tree 1 file changed +22
-13
lines changed
Expand file tree Collapse file tree 1 file changed +22
-13
lines changed Original file line number Diff line number Diff line change 88
99class AnyModel extends Model
1010{
11-
11+
1212 public $ timestamps = false ;
1313
14- public static function table ($ tablename , $ idfield = null , $ options = []){
15-
14+
15+ public static function table ($ tablename , $ options = []){
16+
1617 // Create a new Model and set its table and primary key.
1718 $ Model = new AnyModel ();
18- $ Model ->table = $ tablename ;
19- $ Model ->primaryKey = $ idfield ;
20-
21- // Set any further options passed in before returning
22- Collect ($ options )->each (function ($ value , $ name ){
23- $ this ->{$ name } = $ value ;
24- });
25-
19+ $ Model ->table = $ tablename ;
20+
21+ // Set any further options passed in before returning
22+ Collect ($ options )->each (function ($ value , $ name ) use ($ Model ){
23+ $ Model ->{$ name } = $ value ;
24+ });
25+
2626 return $ Model ;
2727 }
28-
29- }
28+ public function getIDattribute (){
29+ // due to various contortions Model->id will not always be available and it is not possible to set
30+ // primaryKey and have it work so if it is requested and does not exist rather than returning '' (default behaviour)
31+ // raise an error.
32+ if (!isset ($ this ->{$ this ->primaryKey })){
33+ throw new \Exception ('AnyModel::id does not have a value. Please specify actual id field name ' );
34+ }
35+
36+ }
37+
38+ }
You can’t perform that action at this time.
0 commit comments