Livewire has a feature called Offline State. This can be used to notify the User that they have lost their Internet Connection and are offline. You just need to add the wrap:offline attribute to a div like below:

And this div will only be displayed when user goes offline. In this Tutorial, we will show how to implement this functionality into any existing Livewire Project.

We will create a Livewire Component using below command:

This will create a file at app/Http/Livewire/Offline.php.

In our recent Projects we have been using Breeze & Jetstream, both of which uses TailwindCss. It is a common scenario to display the Data in Tabular Form on multiple Screen. Using TailwindCss, there were a lot of duplicate CSS Classes and bloated HTML. In this article we will see how we overcame those challenges.

We have a Product Model. And we need to create a Screen where we can display all the Products in a Table using Pagination. So we created a Route like below:

We created a Controller which returned the Products by…

Laravel Model Factories provide a convenient way to populate your database with Dummy Data during development as well as provide a way to insert Records while running Tests.

You can create a Model Factory using artisan command make:factory. You can also pass the model using -m Flag to specify the Model which will be associated with this Factory.

However, you can also create a Factory as soon as you create a Model by specifying the f flag. So following command will create a Model along with Factory as well as Migration File.

In this Tutorial, we will see how we can create a Livewire Component which will Load More Records from the Database when the User Scrolls to the bottom of the list. And we will do it properly without reloading all the Records when the Component re-renders.

Basically we need to Create a Pagination Component which will initially load all the items of the 1st Page. And then when the User Scrolls to the bottom of the Page, we will need to Load the items of the 2nd Page and append it to the bottom of the list. …

Blade Components have been around Laravel since long, however they gain immense popularity with the release of Jetstream. Jetstream uses Blade Components to keep all the Views consistent and helps to avoid duplicating any Html and thereby keeping the things DRY.

Besides Anonymous Components there are Class Based Components as well. However, in most of the cases Anonymous Components are well suited for most Use Cases. In order to define an Anonymous Component, you only need to create a New Blade File in /resouces/views/componentsDirectory.

If we put a card.blade.php at above location with following content:

Blade Directives provides a convenient and clean way to display data in View. There are various Blade Directives available like @if, @for, @foreach, while which have similar syntax as their PHP Counterparts. Also, we have slightly more robust Directives like @auth, @guest etc.

It is entirely possible to create your own Custom Directives as well. Suppose you want to display the Date in a particular format through-out your App. You can easily do so using a Custom Blade Directive.

You need to register all your Custom Blade Directives boot method of the AppServiceProvider. We can call the directive method of…

Laravel SoftDeletes

It is often said that Digging into Laravel Codebase is one of the best method to understand how the Laravel works under the hood. It also helps you to pick up some of the best practices being used in the Framework. So I decided to dig and understand how Laravel implements Soft Deletes Functionality.

For those of you who have not used Soft Deletes Feature, it can be implemented simply by including a SoftDeletes Trait on your Model. Eloquent will then make sure that when Model are Deleted, they are not actually removed from the Database. Instead it will set…

If you have been developing with Laravel, you would have definitely used Artisan Console make commands. They are used to create a variety of classes like Controller, Model, Request, Jobs, Migrations etc. These make commands comes up with a variety of arguments and options so as to customize the Class created.

Have you ever wondered how Laravel creates these files. It turns out Laravel uses what are known as Stub files.

Laravel Stub

These Stub Files can be seen as the Template File of the Final File to be generated. …

How to Create Migrations in Laravel

You can create a migration file using the Laravel make migration command. You need to specify a meaningful filename like below:

If you are creating migration to add a new table, you should pass --create parameter along with table name. This will add some Boilerplate code to both up() and down().

If you are looking to modify a table, you should consider using --table parameter to add some Boilerplate code.

Pro Tip: You can simultaneously create a migration when you are creating a Model using make:model…

Route Model Binding

When I first started working with Laravel, one of the very first piece of code that I came across was similar to following:

So when I went to URL /post/1, the Post with id 1 was available inside the controller as variable $post. I didn’t had to fetch myself anything from the Database. If I entered a URL with id that did not existed in the Database, I was even redirected to a 404 Page. Even though everything was working fine, I had…

Saurabh Mahajan

Freelancer Developer.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store