Laravel 5.6 – New @method and @csrf Blade Directives

Laravel is gonna introduce two new Blade Directives as part of 5.6 release, @method and @csrf Directives. In the current Laravel 5.5 version, we are doing the following at the top of forms to create hidden inputs for the CSRF token and the spoofed HTTP method – In the Version 5.6, you can use new […]

Laravel 5.5 – How to log all Eloquent Queries

In this post, I will show you simple method to log each and every Eloquent Query of your application executes. We gonna log queries to the storage/logs/laravel.log file. To log database queries we gonna add a database calls lister as shown in the below example. Open your app/Providers/AppServiceProvider.php and add following code to boot() method: […]

Laravel 5.5 – Custom Blade::if() Directives

In Laravel 5.5, writing custom blade if Directives is pretty easy. Using this new feature, you can write simplified and clean if statements in your views. Imagine, you have to check, if the user is admin or not, in this situation you general check for two conditions first you will check whether the user is […]

Laravel 5.5 – New Blade Directives , @auth and @guest

As part of Laravel 5.5 version release, Laravel introduced new blade directives called @auth and @guest.As the name implies both can be useful to determine if the current user is authenticated or guest. In the previous versions of Laravel to check user authentication status we’d used @if directive with the combination of Auth()->check(). But the […]

Laravel 5.5 – DD and Dump in Collections

Laravel offers two new useful debugging methods dump() and dd() as part of Laravel 5.5 version release. These methods are added to Collections, it means you can call dump() and dd() on collection instances. In previous Laravel versions, when debugging collections we’d assign a variable to a collection then keep dumping the variable as we […]

Laravel 5.5 – Optional Objects

Laravel 5.5 includes a new Optional class with a new helper() function, which you can think of as a generic null object implementation. The point of the optional() class and helper is to prevent situations like where you need to fetch a property from a relationship and if its empty this optional helper gracefully handles […]

Laravel 5.5 – Dynamic templates with View::first

Laravel 5.5 is introduced a new feature called dynamic view loading and it makes your controllers simple and more expressive when dealing with dynamic templates. Using This feature we can avoid plain old conditional statements to load the appropriate template for the request. For example, let’s assume you have different pages and some page have […]

Laravel – Generate PDF file from view

We gonna use barryvdh/laravel-dompdf Laravel package to generate PDF files from view file. This package is just a wrapper around DOMPDF library. Installtion Use below composer command to install the package After installing laravel-dompdf, add the ServiceProvider class to the provider’s array in config/app.php You can optionally use the facade for shorter code. So when […]

Laravel 5.5 – The Route::redirect method

Laravel 5.5 introduced new Router class method called redirect, which gives the flexibility to redirect to other URLs directly without creating a controller or closure. How to use Route::redirect() Let’s define a route with Route::redirect() method, if user tries to access http://localhost:8000/contact page, redirect the user to http://locahost:8000/contact-us page. The Route::redirect() is very useful method […]

Laravel 5.5 – The Route::view method

Laravel 5.5 introduced new Router class method called view, which gives the flexibility to render the view file directly without creating a controller or closure. This is not a great big feature, but it simplifies your code and removes a couple of files. How to use Route::view() Let’s define a route with Route::view, to access […]

How to change created_at and updated_at column names in Laravel

You can easily change created_at and updated_at column names by overriding CREATED_AT and UPDATED_AT constants in your Eloquent model. Example #Task Model Let’s assume you have a model called Task and it has columns called createdAt and updatedAt. But Laravel tries to insert data created_at and udpated_at column by default. So in order to inform […]

How to force download files in Laravel?

Giving download option to the user is a pretty common requirement in today’s web apps for the variety of reasons. For example, if your application is related to online shopping, you might need an invoice download feature, in this scenario, you might need to force the user’s browser to download the file at the given […]

How to Create APIs in Laravel 5.5 using API resources

In this post, I will show how easy it is to use API resources to build REST APIs. In the previous Laravel REST API tutorial, I have used Fractal 3rd party library to control API response data. In Laravel 5.5, we now have API resources and these resources are literally developed based on Fractal.Now we […]

Build REST apis with Laravel 4.2

Create a brand new Laravel Project with below command Configure Your Database Open config/database.php file and update it with your database details as shown below Create Migration files and tables We gonna have users and areas tables, so lets create migration file with below commands, which will create creates new files in your app/database/migration directory […]

Laravel 5.5 New feature- Fresh Migrations

In Laravel 5.5 a new Artisan command added to migrate: namespace. This is similar to the existing migrate:refresh option, however, rather than rolling back your existing migrations, migrate:fresh drops all the table and migrates them from scratch. The only difference between a refresh command and fresh command is, the fresh command simply drops all the […]