use connection name in laravel Eloquent

Yes, its possible to set connection name if your model extends to
Illuminate\Database\Eloquent\Model;

$profile = UserDefaultProfile::setConnection('your_connection_name_goes_here')->where('','')->select('');
 $input['user_id'] = $request->user_id;
        $input['page']=$request->page;
        $lang=$request->lang; //$lang Variable for connection name for a particular database
        $input['ip']= request()->ip();//request()->getClientIp();
        $user = CalActivity::on($lang)->create($input);
        $success['a']="";
        return $this->sendResponse($success, 'activity record successfully.');

Leave a Reply