I am using Laravel and need to run raw sql query from a Model/Repository class
INSERT INTO calendar
(room_id, date, default_count, default_price)
VALUES ('1', '2017-01-02', '2', '400004')
ON DUPLICATE KEY UPDATE
default_count = VALUES(default_count), default_price = VALUES(default_price);
ex. When I insert data from UserRepository
$this->users->insert(['email' => 'john@example.com', 'votes' => 0]);
I need some kind of method to get DB connection and run sql via model
//Something like
$this->users->execute($sql);
I saw Laravel has updateOrInsert()
method but I need to run this for multiple data sets at once.
How can I run raw sql query via the model class or repository?
Thanks
UPDATED - SOLVED
I went through Eloquent Model Sourcecode and found I can get connection from getConnection() method
$this->users->getConnection()->statement($sql);