0

Sometimes when using the php artisan tinker console I do something like the following:

$int->groupBy('tracking_code')->toArray();

instead of:

$a = $int->groupBy('tracking_code')->toArray();

If the operation is very complex and/or is on lots of records, it can be a pain to repeat with the variable assignment. So my question is whether the result of the last command is stored anywhere so I can manipulate it without having to wait for the operation to complete a second time?

kaan_a
  • 3,503
  • 1
  • 28
  • 52

1 Answers1

3

Tinker uses PsySH as the REPL.

$a = $_

$_ is a magic variable that holds the result of the last successful execution.

You can find documentation for PsySH on its website:

PsySH

lagbox
  • 48,571
  • 8
  • 72
  • 83
  • I have a blog post that goes over Tinker and PsySH features (and the exact use case you are asking about): [asklagbox - blog - Tinker all the things](https://asklagbox.com/blog/tinker) – lagbox Feb 16 '21 at 04:24