Object-Relational Mapping with Eloquent

For this lab, you will set up a few Eloquent models and write some queries. Start by creating a GitHub Gist called lastname_firstname_lab1_eloquent.md. Write the code for each question in triple back ticks. Here is an example of what your lab submission should look like. Include a comment at the top of the code block for models to specify the location of that model.

To test out your code, use php artisan tinker.

  1. Find all customers who work for "Apple Inc.".
  2. Find invoice 5 and update its BillingAddress to "123 Sesame Street".
  3. Given $theWho = Artist::find(144), create a new album for $theWho.
  4. 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.
  5. 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.

Submission

Send an email to me and the TA with the link to your GitHub Gist. Please use the subject line ITP 405 Lab Submission - Laravel 3.