8

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

1

3 Answers 3

18

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

Sign up to request clarification or add additional context in comments.

1 Comment

Wow this is huge! What a great tip 👏
14

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

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

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.