{ Laravel snippets }

Caleb Porzio

Caleb Porzio @calebporzio

@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": $year1->zip($year2, $year3)->first()

Tim MacDonald

Tim MacDonald @timacdonald87

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

Tim MacDonald

Tim MacDonald @timacdonald87

? Want to thin out your @laravelphp models? You can relocate scopes to dedicated builder object. Gain: ✅ Thinner models ✅ Click through in your editor ✅ Static analysis (if that's ur bag) Lose: ❎ Having every co-located Step 1: Make a custom builder https://t.co/yr8UZs0gB7

Chris Fidao

Chris Fidao @fideloper

? 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

Jonathan Reinink

Jonathan Reinink @reinink

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

Daily Web Dev

Daily Web Dev @dailywebdev

? 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

Daily Web Dev

Daily Web Dev @dailywebdev

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

Rasmus C Nielsen

Rasmus C Nielsen @rasmuscnielsen

? 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