@jmlallier Here's when ->zip()'s useful:
Taking vertical slices of horizontally grouped data (think rows and columns in a DB).
If each row is a "year", & each column is "sales/mo" (12 columns), you could get "January sales over 3 years like so":
Just found out you can pass "null" to array_map, and it behaves the same as ->zip() ? https://t.co/EkPUpWHO9m
? Here's an undocumented hidden @laravelphp gem. Did you know you there's a shorter way to retrieve models in a chunked way? ?
#laravel #php https://t.co/qcVr5bCqGZ
Step 2: Return your dedicated builder from the `newEloquentBuilder` method on your model.
? Scopes on your model will continue to function, so you can progressively refactor if you need. https://t.co/mEXv7MZz80
? Want to thin out your @laravelphp models? You can relocate scopes to dedicated builder object.
✅ Thinner models
✅ Click through in your editor
✅ Static analysis (if that's ur bag)
❎ Having every co-located
Step 1: Make a custom builder https://t.co/yr8UZs0gB7
Do yourself a favor and work to make your code more readable. Even simple conditional checks could take a few seconds to understand 6 months from now ? #php #laravel #clean #code https://t.co/yxrqvs1wgV
?tip from my pairing session with @stauffermatt
If you want to programmatically send input to Artisan Tinker, just echo your input and pipe it to Tinker.
(Works nicely for setup scripts) https://t.co/MxHHpQisbu
? Testing simple S3 uploads with randomized file names in Laravel? Use `Storage::fake` and real-time Facades. Handled. https://t.co/LIBfHbLQxD
? A very useful trick is creating calculated attributes on your Model classes - you can treat them like any other column, e.g.
Foo::find(1)->recently_updated; // boolean https://t.co/mrgwLqxxUg
?? The single greatest use case for Laravel's "retry()" helper function: Pesky Dusk Tests
? Did you know "->pluck()" (in Laravel Collections) accepts a second param that specifies a return key? I certainly did not. Cool. https://t.co/bBPg4TTADP
? #Laravel tip for your schedulers.
Ping a url after a command has finished!
⚡️Give me a follow for more tips! https://t.co/ccDpTEb5au
Here's a neat trick for soft deleting relationships in @laravelphp. ?
When you delete a record, immediately also soft delete any child records. ?
Later, when you restore the parent, automatically also restore all child records that were deleted when the parent was deleted. ? https://t.co/YsYKWtu00R
? Persist request data when redirecting in Laravel with this trick:
Chain withInput() onto your redirects and the request values will get persisted to the redirect location - by flashing data to the session under the hood.
Includes querystrings and POST data
#php #laravel https://t.co/8Vv7QMvfyl
Quick #Laravel tip of the day: we can perform validation not only on Request or $request->all(), but on ANY array. See example code from Laravel package, validating the passed options. https://t.co/rGy1nwwxId
Do you create your own macros in @laravelphp? Consider creating small classes for each one to keep things nice and neat! s/o to @tillkruss for showing me this approach ? #laravel #tips #php https://t.co/wjxLQ8RE3I
Being able to hook into different parts of your Laravel app is invaluable. Here are a few ways you can hook into various stages, such as after a route match, before template compilation, after query execution etc.
(this would sit inside a service provider ?) #laravel #php https://t.co/yjhhEphcCL
?Laravel Tip: Use the DB::unprepared() method to import raw sql files. Of course your Laravel DB schema should match with .sql file.
#Laravel #laravelphp https://t.co/9wGZobI8CR
? When testing API validation responses in #laravelphp you may use the $this->postJson() method rather than $this->post().
This will ensure you get a JSON response rather than the application actually throwing an exception. https://t.co/pDIvSx9yi5