Comments (12)
@securit To set up the macro?
Preselect a block of text in your editor like a query (doesn't matter for just setting it up)
Edit -> Macros -> Start Recording
Edit -> Join Lines
Edit -> Copy
Edit -> Undo
Edit -> Macross -> Stop Recording
Give it a name to save it
Then set it a hotkey in your keymap settings:
Now to use the macro you just highlight everything you want to toss in to tinker and hit your new hotkey.
from tinker.
Thanks to @DanRibbens for his genius idea! 🙂 🎉
In PhpStorm, join lines
command has a default shortcut - CTRL + SHIFT + J
(on a mac it looks like this: ^ + ⬆️ + J
).
from tinker.
Came here trying to figure out the same issue. Instead of changing terminal input behaviour I decided to add a macro for copying joined lines. With this I can select a block of code, press the hotkey assigned to the macro, then paste in the terminal.
In PHPStorm it looks like this:
from tinker.
Same idea of @DanRibbens but With Atom:
we can select multiple lines and join them as one line using ctrl + j
from tinker.
Tinker does support multi-line statements.
from tinker.
:)
from tinker.
Nope!!! I always need to remove linebreaks.
>>> $d = DeviceCamera::with([
... 'device' => function ($query) {
... $query->select(
... 'devices.id as device_id', 'name as camera_name', 'slug as webcam_name'
... )->groupBy('devices.id');
... },
... 'device.device' => function ($query) {
... $query->select(
... 'id', 'id as camera_id', 'camera_lens_type_id', 'settings',
PHP Parse error: A trailing comma is not allowed here on line 9
>>> DB::raw("cast(settings->>'viewport_order' as int) as viewport_order")
=> Illuminate\Database\Query\Expression {#1375}
>>> )->groupBy('id');
PHP Parse error: Syntax error, unexpected ')' on line 1
>>> },
PHP Parse error: Syntax error, unexpected '}', expecting EOF on line 1
>>> 'deployments' => function ($query) {
PHP Parse error: Syntax error, unexpected T_DOUBLE_ARROW on line 1
>>> $query->select(
... 'deployments.id as deployment_id', 'vessel_id'
from tinker.
Ahhhh. It lets you paste the first few lines 😄
Trailing commas in function calls, though.
I just pushed a fix to the develop
branch on PsySH. Do you mind checking that out and confirming that it fixes your issue?
from tinker.
from tinker.
Hmm. You're getting into places that PsySH / tinker can't help you as much :)
By default PsySH doesn't require semicolons to execute code, as long as the code is syntactically complete, valid PHP. In your case, the line before ->whereHas
is a valid and complete statement, so PsySH just goes for it.
If you were typing this in yourself, you wouldn't be super surprised to see that this happened, and you could just use $_->whereHas
to use the return value of the last line to keep going. But in this case, you're pasting and can't adapt on the fly. Unfortunately, with PHP's libedit implementation, I don't believe it's possible to completely solve for paste.
There is this awesome thing called "bracketed paste" that might help here. It makes pasting into readline much saner. If you're using PHP-with-readline, and it's a new enough readline version, and your terminal app supports it, and the stars align just right :)
Unfortunately it often doesn't work, and when it doesn't it spews escape codes all over the place, so it's not going to be enabled by default, at least for now.
So you have a couple of options:
-
Download the latest dev branch and add
"useBracketedPaste" => true
to your PsySH config. -
If that doesn't work, and you're using PHP with readline (not libedit)… update your
.inputrc
to tell readline you like to paste:set enable-bracketed-paste on
If neither of those work:
-
Switch your coding style to end lines with
->
instead of starting the next line. This will keep a given line from being syntactically complete, and will keep the input buffer open. -
Add slashes to the end of ambiguous lines like this to keep them from executing. In PsySH, if you end a line in
\
, it forces it to keep the input going on the next line. This is kind of a pain, but maybe not as much as removing all the newlines? -
Disable implicit semicolon support. Add
"requireSemicolons" => true
to your PsySH config. This will keep pastes from executing as soon as you've finished a syntactically complete line. Unfortunately, this is a global setting, so if you change it, you'll have to type1 + 1;
to get1 + 1
to get things to execute the rest of the time. -
Switch to a PHP with readline instead of libedit and use bracketed paste!
from tinker.
from tinker.
within your tinker session type the keyword "edit" which would open an editor to write your code. Once your done exit out and the code will execute. You will be able to see the output
from tinker.
Related Issues (20)
- Tinker lost colors HOT 18
- How is idea of making laravel tinker that detect the updates in code instantly? HOT 3
- Add ability to refresh Tinker session from within Tinker? HOT 3
- Contextual binding doesn't appear to work in tinker HOT 4
- Add migrate:install to white listed commands HOT 1
- assert always returns true HOT 2
- Can't open Tinker because of a bad $options argument to Symfony HOT 2
- Commands inside tinker incorrectly parsed HOT 1
- Tinker broken in laravel 9.0.0 HOT 8
- Issue registering StorageLinkCommand HOT 2
- PHP Error: Call to a member function make() on null HOT 5
- Closures not working when using the --execute argument. HOT 1
- stream_wrapper_register(): Protocol hoa:// is already defined in psy/psysh/src/Readline/Hoa/ProtocolWrapper.php:473 HOT 1
- Recoverable fatal error: Object of class Illuminate\Foundation\Application could not be converted to string in Command line code on line 8 HOT 1
- Parse error: Syntax error, unexpected ':' in vendor\psy\psysh\src\Exception\ParseErrorException.php on line 40. HOT 1
- The destructor is not executed HOT 2
- Loop only returns the last value if the curly brackets start on a new line HOT 5
- Output cleared and missing colors after upgrading to Laravel 9 HOT 4
- First time i open tinker, i have to dispatch a job twice to get it pushed to queue HOT 1
- Silent crash when initializing a PDO connection to PostgreSQL HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tinker.