Laravel

How to check if the result is empty for eloquent collection in Laravel?

A lot of times when coding we might encounter a problem where we have to check if the result we are getting has some data or not. But when we are working with eloquent results, even if it is empty, the function ’empty()’ holds false as well as ‘if($result)’ always holds true. So to find …

How to check if the result is empty for eloquent collection in Laravel? Read More »

Altering Table Through Migrations Laravel

It is a very difficult job to change the column name or type once it is migrated and has contents. In order to modify the column, we need to create another migration where we state the modifications. Let us create a migration first by using the following command Php artisan make:migration change_post_description_to_nullable_in_tbl_posts —table=tbl_posts This will …

Altering Table Through Migrations Laravel Read More »

Laravel Form Collective Select Tutorial

The select form is a bit complicated among other forms in Laravel collective. It is because we need to follow certain rules to make it work. First of all the code of the form looks like this Form::select(“postId”, $post, null, [‘class’ => ‘form-control’]); Let me explain the code first. We need to store the value …

Laravel Form Collective Select Tutorial Read More »

All about Migration Rollbacks

The examples are focused on how to roll back migrations on Laravel. This rolls back the last migrations Migration rollback according to steps. The below code will roll back the last two migrations. Change the steps to roll back accordingly. If you want to roll back as well as remigrate the last migrations To roll …

All about Migration Rollbacks Read More »

Using When Condition Inside a query in Laravel

Similar to the previous article I wrote about using the IF condition inside a query (Click Here for the link), I asked Reddit for the best way to handle the query in my previous article and I learned a bunch of ways where we can get the same solution. One of them using the when …

Using When Condition Inside a query in Laravel Read More »

Using IF Condition Inside a query in Laravel

The task for me today was to filter the products as per their status i.e if they are published then their value would be 1 and if they are unpublished then their value would be 0. But I didn’t want to create three queries for them, one for each condition. Therefore, I used the if …

Using IF Condition Inside a query in Laravel Read More »

Check if the checkbox is checked or not.

As per my previos post, what I did was get all the categories, now I wanted to change the categories checkbox status using ajax. For this I had to get the category ID and the checkbox status using javascript. My previous Code What we are doing here is checking if the input class with ‘checkbox_id’ …

Check if the checkbox is checked or not. Read More »

How to compare data in a relationship table with the main table without using more than one loop?

I had this problem where I had to get all the names from one table and get relation from another table and check if the relationship exists or not and if it exists, the checkbox must be checked. Let me clear the problem first. I need to show all the categories of the posts. So …

How to compare data in a relationship table with the main table without using more than one loop? Read More »