Execute Raw SQL Query in Laravel using getPdo()

To execute raw query in laravel we should use a php pdo. First we need to get a laravel database connection with pdo by getPdo() method then prepare sql by prepare() method and execute by execute() method. Then check the result from select or insert values.

The following example is based on different raw sql queries.