How to return a downloadable file in Laravel
If you need to return a downloadable file in Laravel, just do it with this easy technique – enable the download method on the response object. For example:
If you need to return a downloadable file in Laravel, just do it with this easy technique – enable the download method on the response object. For example:
Hello friends. Sometimes you need to run tests that rely on specific time in the past or in the future. There is a useful trick to fake time for that purpose. Just set fake timestamps using now() helper or Carbon class. Here is the example:
When you use the Laravel eloquent models on a non-default database connection, the default database transaction will not work. You have to specify the DB connection type before opening the transaction.
Hello friends! In Laravel, you can utilize the shortcut for “higher order messages” that come with collections. This is extremely useful for performing common actions. See the code below:
The best and clean way is to run the terminal command that composer documentation tells: You can also remove multiple packages in a row: Also, don’ forget to remove code that utilizes the package.
If you catch this error, you should check your Laravel version. Since the version 8, you have to use another helper:
There is an orderByRaw method in Laravel that lets you write your custom raw query to retrieve records by order. See the following code example with the task “Get the nearest office for given latitude and longitude”. App\Models\Office.php: To get the nearest office for a given latitude and longitude (columns lat and lng):
Often times you need to filter your Model records based on the created_date field. With Laravel, you can make scope Methods after() and before() and use them like below. In case multiple of your Models needs these methods, you can move them to Trait.
One of the first questions they have for people who get started with Livewire is why there are so many separate requests to the server. As you may know, with a change on the Livewire model field, there’s an ajax request or API request. And there are just too many requests to load on the […]
If you like to use route names in your Laravel projects, this tip might be helpful to you. You can assign the named method on a route instance to find if the current request was directed to a given named route.