Home > Software engineering >  Create table in database with value from array object in laravel
Create table in database with value from array object in laravel

Time:08-27

i have an array object from query builder like this for example

$data = DB::table('list_cars')->select('car_name', 'car_id')->get();

I want to make new table with schema structure from result query builder $data above. Is it possible to make it in laravel 8? result will be 2 field (car_name and car_id).

CodePudding user response:

You can use raw DB queries like for example:

DB::statement(
    "CREATE TABLE <tablename> AS "
    .DB::table('list_cars')->select('car_name', 'car_id')->toSQL()
);

CodePudding user response:

Yes, Sure you can use SQL raw in Laravel and create table please attention this Question: Laravel create table with raw string

  • Related