0

Sometime, I can make can use Eloquent for complex login in laravel. So, i need run a big raw query. How to do that? Example: i need run

Insert Into ..............
       Select..............
       Join....
       Join....
       Where...............
       ...............................................................
  • 2
    https://laravel.com/docs/master/queries#raw-expressions – xNoJustice Jul 31 '20 at 08:38
  • Does this answer your question? [How to execute raw queries with Laravel 5.1?](https://stackoverflow.com/questions/33049511/how-to-execute-raw-queries-with-laravel-5-1) – Egretos Jul 31 '20 at 11:42

2 Answers2

3

May be you're finding for this solution. you can using it for resolve your problem.

$yourComplexQuery = "
    Insert Into ..............
    Select..............
    Join....
    Join....
    Where...............
   ...............................................................
";
DB::select($yourComplexQuery);
Thanh Nguyen
  • 350
  • 3
  • 6
0

You can use the DB Facade, in addition you could use its raw methods.

DB::table('tableName')->selectRaw()...

https://laravel.com/docs/master/queries#raw-expressions

If this is not raw enough for you, you can simply define your sql query:

$query = "Insert Into ..............
       Select..............
       Join....
       Join....
       Where...............
       ................... ";

and insert it into the DB::select($query);

Aless55
  • 2,273
  • 1
  • 13
  • 25