Software Engineer · Teacher · Author · Vegan

Laravel 3

Create a repo with a README.md. In this file, write the Eloquent code for each question in code fences (triple back ticks). Here is an example of what your submission should look like. If you click on “Raw”, you can see the Markdown. If your Markdown submission is not formatted like the example, you will lose points.

To test out your code, use php artisan tinker.

  1. Find all tracks with the genre “Metal”.
  2. Find all customers who work for “Apple Inc.”.
  3. Find invoice 5 and update its BillingAddress to “123 Sesame Street”.
  4. Given $theWho = Artist::find(144), create a new album for $theWho. Use relationships instead of accessing $theWho->ArtistId directly.
  5. What is the total of all invoices in 2012?
  6. What is the average track length?
  7. Create a relationship between an invoice and invoice items such that all invoice items for an invoice can be accessed through an items property off of an invoice object.
  8. Create a relationship between an invoice and invoice items such that the invoice can be accessed from an invoice item object through an invoice property.

NOTE: The primary key in the invoice_items table is NOT InvoiceItemId as you might expect. The primary key of invoice_items is actually InvoiceLineId. If you open up the database in SQLite from the command line, (see this page if you forgot), you will see that. This is pertinent to the last 2 questions.

Some helpful resources:

Submission

https://classroom.github.com/a/EtqkzX4o