25.06.2018 Views

Full-Stack Vue.js 2 and Laravel 5

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Inserting the data<br />

In order to insert the data, we'll use the DB facade again. This time we'll call the<br />

table method, which returns an instance of Builder. The Builder class is a fluent<br />

query builder that allows us to query the database by chaining constraints, for<br />

example, DB::table(...)->where(...)->join(...) <strong>and</strong> so on. Let's use the insert method<br />

of the builder, which accepts an array of column names <strong>and</strong> values.<br />

database/seeds/ListingsTableSeeder.php:<br />

public function run()<br />

{<br />

$path = base_path() . '/database/data.<strong>js</strong>on';<br />

$file = File::get($path);<br />

$data = <strong>js</strong>on_decode($file, true);<br />

DB::table('listings')->insert($data);<br />

}

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!