DevonDahon
DevonDahon

Reputation: 8350

Laravel Artisan Tinker : write command on multiple lines

How can I write a command on two lines with Laravel Artisan Tinker ?

User::whereEmail('[email protected]')
->get()

PHP Parse error: Syntax error, unexpected T_OBJECT_OPERATOR on line 1

Upvotes: 6

Views: 2951

Answers (3)

mselmany
mselmany

Reputation: 434

If I'm going to write several lines of code, I usually prefer a dedicated 'experiment' route over tinker. It becomes somewhat Tinkerwell like.

Route::get('/experiment', function () {
    User::whereEmail('[email protected]')
        ->get();
});

With Xdebug set up, you can watch variables, trace the code line by line etc.

If you are concerned about publishing the experiment route, you may block it in the production with something like the following line before your experiment code:

Route::get('/experiment', function () {
    app()->isProduction() && abort(403, 'This route is only for experimenting.');

    return User::whereEmail('[email protected]')
        ->get();
});

Note that I've also added a return. It is useful if you don't bother using a debugging tool (like Xdebug). You can easily see the return value where you trigger the route from.

Upvotes: 0

1FlyCat
1FlyCat

Reputation: 383

You can type edit, which launches an external editor and loads the generated code into the input buffer.

Upvotes: 16

Noman Saleem
Noman Saleem

Reputation: 506

Use the \ character to force the REPL into multi-line input mode:

>>> User::whereEmail('[email protected]') \
... -> get()

Upvotes: 12

Related Questions