Lesson list · Lesson 5 of 5

The Basics · Lesson 5 of 5

Working with the Database

Describe your tables with migrations, then read and write rows with Eloquent.

1 min 0 comments

A migration describes a table in PHP, so the whole team gets the same database structure.

Schema::create('posts', function (Blueprint $table) {
  $table->id();
  $table->string('title');
  $table->text('body');
  $table->timestamps();
});

Reading and writing

With the table in place, Post::create() saves a row and Post::latest()->get() reads them back, newest first. No SQL needed for everyday work.

Discussion

Log in to join the conversation. Log in

R

Rizky A. on the class page

Is this class enough to start building my own project?

C

Codesakura Author

Yes. After the last chapter you can build a simple CRUD app on your own.