File tree Expand file tree Collapse file tree 1 file changed +8
-1
lines changed
Expand file tree Collapse file tree 1 file changed +8
-1
lines changed Original file line number Diff line number Diff line change @@ -10,7 +10,6 @@ class AnyModel extends Model
1010{
1111
1212 public $ timestamps = false ;
13- protected $ primaryKey ; // increase visibility of primaryKey to allow it to be set in options
1413
1514
1615 public static function table ($ tablename , $ options = []){
@@ -26,6 +25,14 @@ public static function table($tablename, $options = []){
2625
2726 return $ Model ;
2827 }
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+ }
2935
36+ }
3037
3138}
You can’t perform that action at this time.
0 commit comments