Don't forget to use Carbon constants
When working with dates and times, we use awesome Carbon class, right? And there's a lot of small things in it which we might not even know. I will give you one example today.
In-depth Laravel tutorials covering advanced topics, real-world examples, and best practices.
When working with dates and times, we use awesome Carbon class, right? And there's a lot of small things in it which we might not even know. I will give you one example today.
Two days ago Taylor Otwell released a new minor version of Laravel framework - 5.2.22. Along with some small fixes, there are a few new functions, let's look into them.
Today I want to show you a useful package I've found - it's called Laravel Hackathon Starter and created by Prosper Otemuyiwa. It gives you a perfect start for quick project you need.
In PHP world there are two big groups of developers - those who work with Content Management Systems (WordPress, Drupal etc.) and those with frameworks (Laravel, Symfony etc.). And rarely people work with both worlds - cause their philosophy is fundamentally different. But when you get a new project from a client - how to decide whether Laraver is the best choice? Or maybe simple WordPress would be enough and would save time/money? Sometimes it's not that easy to decide. So here are my tips - questions you need to ask.
If we add a foreign key column in our migration file in function up(), we need to make sure that foreign key would be dropped in down() function, right? The thing is that you need to remember longer foreign key name to drop it by name. What official Laravel documentation doesn't say is that there's a more convenient way.
If you have a longer form in your project, it takes time to fill it in. And if it's hidden under user session, it will time out - by default, in 120 minutes. Seems like enough time, but what if a user left the form open for longer time, went for coffee or something, and then tries to finish it after a while? There is a package to make session active.
Laravel has Resource Controllers which allow us to quickly set up create/read/update/delete operations. But the trickiest one is probably DELETE one - we have to create a separate form for it. With submit button. What if in our table Delete is not a button, but a link? An icon with a link on it. Here's how to get the whole thing working with link instead of a button.
Laravel has convenient database migrations mechanism, which allows us to track database changes and easily roll them back if needed. But what is hiding behind the scenes? What if we need to know actual SQL queries that have been generated during the migration? Or another scenario - what if we want to check the SQLs before they are actually run? There's a trick for both of it.
With Laravel, we get used to command line commands like composer install or artisan migrate. But what if we have only shared-hosting from client, with only FTP access and phpMyAdmin to manage database? Laravel is still usable in this case, but there are some tricks you need to make it work.
Today I want to tell you about one "hidden" Laravel feature which is in the system but not in documentation - replicate. This function allows you to make a copy of a row in the fastest way possible.