1 00:00:00,490 --> 00:00:01,392 Welcome back. 2 00:00:01,392 --> 00:00:06,633 In this section we'll explore Tinker, Laravel's built in REPL tool. 3 00:00:06,633 --> 00:00:09,574 Tinker allows us to easily read, add or 4 00:00:09,574 --> 00:00:14,042 modify records in the database with a few simple commands. 5 00:00:14,042 --> 00:00:18,866 In the next video, I'll show you how to run Tinker to interact with the database 6 00:00:18,866 --> 00:00:20,673 in our Laravel application. 7 00:00:20,673 --> 00:00:22,090 See you there. 8 00:00:22,090 --> 00:00:27,038 Before we can start using Tinker, let's add the course 9 00:00:27,038 --> 00:00:32,301 model to our index function in the AppController.php file 10 00:00:32,301 --> 00:00:37,892 located in the App/Http/Controllers directory like this. 11 00:00:37,892 --> 00:00:42,721 Here, we need to add, All of the courses, 12 00:00:48,304 --> 00:00:57,547 Inside of the course model, And this denotes all of the courses. 13 00:00:59,880 --> 00:01:05,972 The library view will return all of the courses inside of the Course model. 14 00:01:05,972 --> 00:01:09,814 Remember that before we can test out the app controller, 15 00:01:09,814 --> 00:01:11,822 we need to seed our database. 16 00:01:11,822 --> 00:01:15,376 So we're done editing the app controller file for now. 17 00:01:15,376 --> 00:01:20,100 Next, let's start using Tinker by opening the terminal and 18 00:01:20,100 --> 00:01:23,535 typing this command, php artisan tinker. 19 00:01:25,802 --> 00:01:30,566 Once you enter the command, you'll start up the tinker environment where you 20 00:01:30,566 --> 00:01:34,539 will enter commands to interact with your Laravel application, 21 00:01:34,539 --> 00:01:36,284 most notably the database. 22 00:01:36,284 --> 00:01:41,404 If you try to access the database now using the course all command, for example, 23 00:01:41,404 --> 00:01:46,012 we won't get anything back because we haven't seeded our database yet. 24 00:01:46,012 --> 00:01:48,872 Which we will do in an upcoming video. 25 00:01:48,872 --> 00:01:52,789 Tinker can also carry out basic arithmetic like this. 26 00:01:56,088 --> 00:01:59,106 1 plus 1 equals 2. 27 00:01:59,106 --> 00:02:02,830 Variables are also available in the Tinker environment. 28 00:02:02,830 --> 00:02:07,841 For example, we can define variables and concatenate them like this. 29 00:02:07,841 --> 00:02:12,521 $a- 'Number ', and 30 00:02:12,521 --> 00:02:19,314 it returns the value "Number ". 31 00:02:19,314 --> 00:02:24,435 If we continue, $b 32 00:02:24,435 --> 00:02:29,151 equals five=5, 33 00:02:29,151 --> 00:02:37,704 concatenation, space 'Alive! 34 00:02:37,704 --> 00:02:42,811 "5 Alive!" Continuing 35 00:02:42,811 --> 00:02:46,807 with the variables, 36 00:02:46,807 --> 00:02:52,585 $c = $a concatenation $b. 37 00:02:52,585 --> 00:02:59,683 "Number 5 Alive!" If you don't know what movie this is, Google Short Circuit. 38 00:02:59,683 --> 00:03:04,202 Moving on, you can also type the ls command to list local, 39 00:03:04,202 --> 00:03:08,919 instance, or class variables, methods, and constants. 40 00:03:08,919 --> 00:03:10,844 If you get stuck at any point, 41 00:03:10,844 --> 00:03:15,321 you can always use the Help command while using Tinker, like this. 42 00:03:15,321 --> 00:03:19,363 To view available commands on a particular topic, 43 00:03:19,363 --> 00:03:24,723 such as the dump object for example, use this command, help dump. 44 00:03:30,002 --> 00:03:34,979 Now that we started using Tinker, we're ready to create our course model, 45 00:03:34,979 --> 00:03:38,182 so we can finally seed and migrate our database. 46 00:03:38,182 --> 00:03:42,588 We're very close to putting everything together, so let's push on through and 47 00:03:42,588 --> 00:03:46,042 build our database records for our Treehouse course library. 48 00:03:46,042 --> 00:03:47,290 See you in the next section.