CCS3310 Software Engineering Methods – Lesson 6

What we did today (summary)

  • How to connect to the Database (the M in MVC) and receive a collection
  • Passing a collection from controller to a view
  • Installing a starter kit (Breeze+Blade) for automatic authentication flow

Instructions:

  • How to use the database: https://laravel.com/docs/11.x/eloquent
  • Find the “Book” migration file at: ccs3310\database\migrations
  • It will look like this <date stamp>_create_books_table.php
  • Update the schema as follows (you may customize it as you wish):
public function up(): void
{
   Schema::create('books', function (Blueprint $table) {
     $table->id();
     $table->string('title');
     $table->string('isbn', 15);
     $table->text('summary');
     $table->date('published_at');
     $table->timestamps();
   });
}
  • run this command to refresh the database: php artisan migrate:refresh –seed
  • Update the book controller with following:
public function index()
{
   $books = Book::all(); //read all books from the database
   echo $books;
}
  • Open HeidySQL and add few records manually.
  • Open a browser and goto ccs3310.test, here you should see Laravel running successfully

Recorded lesson:


References:


All lessons > 

Share