Assignment 3

For this assignment, create a new Laravel application called "assignment-3".

The Tracks Page

Create a Tracks page located at /tracks that shows a table of all tracks sorted by the track name using the orderBy method. Display the following fields:

  1. track name
  2. album title
  3. artist name
  4. media type name
  5. genre name
  6. unit price
  7. minutes and seconds (derived from milliseconds) (tip: see @php Blade directive)

Creating Tracks

Add a link at the top of the page with the text "New track". Clicking this link should take you to /tracks/new. This page should display a form for creating a track. The form should contain:

  1. a text input for name
  2. a select menu populated with all available albums sorted alphabetically
  3. a select menu populated with all available media types sorted alphabetically
  4. a select menu populated with all available genres sorted alphabetically
  5. an input for the unit price
  6. a number input for milliseconds

When the user submits the form, the following should happen:

  1. Server-side validation via Laravel's validation rules. All fields are required. The album, media type, and genere selected must exist in the database. Unit price must be a number greater than 0.
  2. If the form is valid, the track is inserted into the database and the user is redirected back to the Tracks page with a success alert containing the text "The track "TRACK NAME" was successfully created", where TRACK NAME is replaced with the name of the newly created track.
  3. If the form is invalid, display error messages underneath each of the corresponding form controls. The form should also contain the user's invalid form data.

Extra credit (10 points): Renaming a Playlist

Recreate the /playlists page from Assignment 2. This is not part of the 10 extra credit points.

On the /playlists page, display a link next to each playlist with the text "Rename". This link should take the user to /playlists/{id}/edit where the user can change the name of the playlist. Display a text input on this page that is populated with the name of the playlist. The playlist name is required, should contain a maximum of 30 characters, and be unique (see the unique validation rule). If validation fails, display an error message underneath the playlist name input and populate the input with what the user typed in. When a playlist is successfully renamed, redirect the user to /playlists and display some kind of success alert on /playlists with the text "X was successfully renamed to Y" (where X is the old playlist name and Y is the new playlist name) using Flashed Session Data.

This is how to perform an update via the query builder (the DB class): https://laravel.com/docs/10.x/queries#update-statements.

Code Requirements

  • Use Laravel's Blade templating. All pages should use a single layout that you define.
  • All database queries should use Laravel's Query Builder
  • All routes should map to a controller
  • All routes should have a name and all URLs should use the route() helper function

Submission

Create a video with audio using Zoom where you demo your assignment and explain where you fulfilled or did not fulfill each requirement. Put a link to this recording in the README.md file at the root of your project.

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

If you're having problems uploading to GitHub, please zip up your project excluding the vendor folder and email it to the instructor and TA. Please include the Zoom recording URL in the email.