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
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
Use the \
character to force the REPL into multi-line input mode:
>>> User::whereEmail('[email protected]') \
... -> get()
You can type edit
, which launches an external editor and loads the generated code into the input buffer.
Use the \
character to force the REPL into multi-line input mode:
>>> User::whereEmail('[email protected]') \
... -> get()
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.
© 2022 - 2024 — McMap. All rights reserved.