change database connection in laravel model

前端 未结 4 1571
面向向阳花
面向向阳花 2020-12-09 03:57

So i work with Laravel 4.2, what i want is in one of my models use an external database, this is my model code :



        
4条回答
  •  温柔的废话
    2020-12-09 04:41

    I think for a lot of use cases it can be convenient to declare the connection at runtime like this:

    $McibModel = new McibModel();
    $McibModel->setConnection('second_db_connection');
    

提交回复
热议问题