Intro to Tinker3:47 with Jonathan Barrios
In this section, we’ll explore Tinker, Laravel’s built-in REPL tool, powered by PsySH. REPL translates to read-evaluate-print-loop, that is to say, it evaluates a single user input and returns the result. Tinker allows us to easily read, add or modify records in the database with a few simple commands for tasks such as verifying our database contents which we’ll do later in the course. In the next video, I’ll show you how to run Tinker to interact with the database in our Laravel application. See you there.
Welcome back. 0:00 In this section we'll explore Tinker, Laravel's built in REPL tool. 0:01 Tinker allows us to easily read, add or 0:06 modify records in the database with a few simple commands. 0:09 In the next video, I'll show you how to run Tinker to interact with the database 0:14 in our Laravel application. 0:18 See you there. 0:20 Before we can start using Tinker, let's add the course 0:22 model to our index function in the AppController.php file 0:27 located in the App/Http/Controllers directory like this. 0:32 Here, we need to add, All of the courses, 0:37 Inside of the course model, And this denotes all of the courses. 0:48 The library view will return all of the courses inside of the Course model. 0:59 Remember that before we can test out the app controller, 1:05 we need to seed our database. 1:09 So we're done editing the app controller file for now. 1:11 Next, let's start using Tinker by opening the terminal and 1:15 typing this command, php artisan tinker. 1:20 Once you enter the command, you'll start up the tinker environment where you 1:25 will enter commands to interact with your Laravel application, 1:30 most notably the database. 1:34 If you try to access the database now using the course all command, for example, 1:36 we won't get anything back because we haven't seeded our database yet. 1:41 Which we will do in an upcoming video. 1:46 Tinker can also carry out basic arithmetic like this. 1:48 1 plus 1 equals 2. 1:56 Variables are also available in the Tinker environment. 1:59 For example, we can define variables and concatenate them like this. 2:02 $a- 'Number ', and 2:07 it returns the value "Number ". 2:12 If we continue, $b 2:19 equals five=5, 2:24 concatenation, space 'Alive! 2:29 "5 Alive!" Continuing 2:37 with the variables, 2:42 $c = $a concatenation $b. 2:46 "Number 5 Alive!" If you don't know what movie this is, Google Short Circuit. 2:52 Moving on, you can also type the ls command to list local, 2:59 instance, or class variables, methods, and constants. 3:04 If you get stuck at any point, 3:08 you can always use the Help command while using Tinker, like this. 3:10 To view available commands on a particular topic, 3:15 such as the dump object for example, use this command, help dump. 3:19 Now that we started using Tinker, we're ready to create our course model, 3:30 so we can finally seed and migrate our database. 3:34 We're very close to putting everything together, so let's push on through and 3:38 build our database records for our Treehouse course library. 3:42 See you in the next section. 3:46
You need to sign up for Treehouse in order to download course files.Sign up