1

I have an eloquent model, that is using a custom table, coming from the user table.

Like so...

class Appointment extends Eloquent
{   
   public static $table = null;
   public function __construct()
   {
      parent::__construct();

       // Here I load the custom table, from the user table
      // Pull the prefix of the table, and append
      // This works perfectly fine for viewing the data
      static::$table = Auth::user()->tenantTable()."_appointments";
   }

   public static $connection = 'tenant-data';
   public static $timestamps = true;

I can pull, and view the data perfectly fine with this setup. So every user, has their own appointment table.

However, if I change anything and then use eloquent save() method. I get a recursive call, that never ends.

What do I need to change in laravels save() method to get this to work?

And do I have to change it in the core?? Or can I override the save() method in the current model? And if so, how?

Cœur
  • 37,241
  • 25
  • 195
  • 267
Kylie
  • 11,421
  • 11
  • 47
  • 78

2 Answers2

0

I'm almost just guessing but did you try to change the order of your constructor commands? First set the table dynamically and then call parent constructor?

amosmos
  • 1,039
  • 10
  • 20
0

I am not sure what are you trying to achieve but, yes you can override parent ( eloquent's on your case ) save method.

class Appointment extends Eloquent{  
   public function save(){
      //Do your own save stuff 
      ....
      // call Eloquent's save function to finish
      parent::save();
   }
} 
serdar.sanri
  • 2,217
  • 1
  • 17
  • 21