{ Laravel snippets }

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

Andrew Schmelyun

Andrew Schmelyun @aschmelyun

Today I learned about Laravel's replicate method, which returns a new instance of a model with the same attributes as the one you're replicating. You can then make changes to the properties of it before saving! https://t.co/oXRwqtgkfL