6

How can I break to a new line using laravel tinker?

So instead of: $users = User::all(); foreach($users as $user) {echo $user->email;}

I want to be able to write it as follows:

$users = User::all();

foreach($users as $user) {
   echo $user->email;
}

Is it possible?

rook99
  • 1,034
  • 10
  • 34
  • I just tried it and opening a curly brace `{` changes the terminal from `>>>` to `...` and only executes the block when I put in a `}` so... yes it works. You really should try these things out first. That's the whole point of tinkering – apokryfos May 01 '20 at 12:15
  • @apokryfos I did try it before posting my question, and it doesn't change the terminal to `...` – rook99 May 01 '20 at 12:25
  • Ok, never mind I understand what you mean now. I should write `{` at first and then hit Enter. I searched about this before posting my question but didn't find any info... Thank you. – rook99 May 01 '20 at 12:35

3 Answers3

7

Pipe your code into tinker i.e.:

cat yourcode.php | php artisan tinker

I think this might be the closest you'll get to what you want in the current version.

jvndev
  • 300
  • 4
  • 14
2

You can break line using "\n".

Example:

$users = User::all();

foreach($users as $user) {
    echo $user->email . "\n";
}

OBS: Your "\n" needs to be inside a DOUBLE QUOTES

0

You can write code multiple line Windows User: Ctrl + Enter