Skip to main content

Posts

Showing posts from July, 2016

Redirecting with Input in Laravel 5.2

I'm posting this because it was somewhat difficult to put together using the Laravel documentation.  It is *there* in the docs, but it is split between different subjects.  So here it is, all put together for your enjoyment: I generally use redirects either when input fails validation or when the data has been saved and I'm ready to move to the next input page or a "finished" page.  In the case of redirecting with input, we're talking about a validation failure (or some other error).  The related redirect command is pretty straightforward: return redirect() -> back() -> withInput(); The part I had trouble deciphering was how to retrieve that information into my blade view or controller.  Note that the input is "flashed" to a session, which means it does not persist between page loads (it is deleted after the page loads).  Fortunately, it turns out to be very simple to retrieve an input: // Controller: $first_name = old( ' first_na

Do your migrations work both ways?

A recent practice of mine is to verify that my migrations work both ways.  That means migrating, rolling back migrations and then migrating again.  This has helped me find issues that I otherwise would have missed. The issues I find usually have something to do with relationships or migrations that alter tables.  While foreign key relationships can be complicated to deal with, they are great for data integrity and query efficiency.  So do yourself a favor and make sure those migrations always work forwards and backwards!