Verify Database Records with Tinker3:51 with Jonathan Barrios
Now that we’ve created, defined, and connected our Factories and Seeds, we’re ready to have some fun testing our data with the one and only, Tinker.
We're creating significant progress with the initial setup of the database for 0:00 our API. 0:04 Now that we've created, defined and connected our factories in Seeders, 0:06 we're ready to have some fun testing our data with the one and only Tinker. 0:11 Tinker allows you to interact with your entire Laravel application 0:17 from the command line, including the Eloquent ORM, jobs, 0:22 events, and more. 0:26 We'll use Tinker to check the database records for 0:30 the authors and books as well as the relationships that we've assigned. 0:32 To learn more about Tinker, check out the teachers notes below. 0:38 Let's get started. 0:41 Let's use Tinker to verify that we have the author and book test data 0:44 that we're expecting by using the artisan Tinker command like this. 0:49 Now that we're in the Tinker shell, let's retrieve the first author and 0:57 all authors like this. 1:01 Sweet, now that we have verified our fake authors, 1:18 let's verify our books as well like this. 1:21 Nice, our REST API is already returning book entries just as expected. 1:40 Next, open the Tinker shell and let's return the count for 1:46 all authors like this. 1:50 Three authors, isn't Tinker great? 1:58 We can even test our eloquent relationships like this. 2:02 Which returns the author of the first book. 2:16 This returns all of the books by the first author. 2:30 This command returns the number of books. 2:57 How about daisy chained relationships? 3:01 No sweat. 3:03 Awesome job, you set up a Laravel application using composer and 3:22 created factories that generate test data for our API. 3:27 You define the Seeders so 3:31 you can verify the test data in your models and their relationships. 3:34 In the next section, we'll dive into API basics and how we can create a resource 3:39 controller with CRUD operations to control our author and book models. 3:44 See you there. 3:50
You need to sign up for Treehouse in order to download course files.Sign up