Permalink
Switch branches/tags
Nothing to show
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
executable file 58 lines (38 sloc) 2.29 KB

Practice work

Throughout lecture and your own practice work, we'll need a way to test out examples.

For example, in the notes on Environments, we learn that you can get config variables using the config helper method, e.g.:

dump(config('mail.driver'));

Where should you run this command to test it out? You have a few options, described below.

(Side note: the above code also uses the Laravel helper method dump which we'll use a lot when working locally and we want our app to simply output some data/info so we can examine it.)

Option 1: Practice route

You can create a temporary practice route:

Route::get('/practice', function () {
    dump(config('mail.driver'));
});
  • Pros: Quick and easy
  • Cons: Not ideal to clutter up your routes file, but not a big deal if you remember to remove it when done.

Option 2: Practice controller

Create a controller dedicated to practice work, PracticeController.php, with a dynamic route to access the individual methods. This is what I'll do for lecture.

Refer to the following foobooks' files to see how it's set up:

Option 3: Artisan Tinker

If you run php artisan tinker in your Laravel project, you'll get an interactive console for tinkering with your app.

Example:

/Applications/MAMP/htdocs/foobooks (master)  $ php artisan tinker
Psy Shell v0.7.2 (PHP 5.6.25 — cli) by Justin Hileman
>>> dump(config('mail.driver'));
"smtp"
=> "smtp"

Tip: Hit ctrl + c to exit the Tinker console.

  • Pros: Convenient for quick examples, requires no additional files to clutter up your project.
  • Cons: For lecture purposes this isn't ideal, because there will be no history of the examples, but feel free to use during your own practice.