Ruthie  Blanda

Ruthie Blanda

1625226720

Laravel: Be Careful with whereHas Performance in Eloquent

Quick video, comparing two Laravel queries that perform almost the same task - querying by relationship. WhereHas() or join()?


Support the channel by checking out our products:

#laravel #eloquent #wherehas performance

What is GEEK

Buddha Community

Laravel: Be Careful with whereHas Performance in Eloquent
Ruthie  Blanda

Ruthie Blanda

1625226720

Laravel: Be Careful with whereHas Performance in Eloquent

Quick video, comparing two Laravel queries that perform almost the same task - querying by relationship. WhereHas() or join()?


Support the channel by checking out our products:

#laravel #eloquent #wherehas performance

Seamus  Quitzon

Seamus Quitzon

1595205213

How to perform migration rollback in laravel

As we know that laravel migration provides very simple way to create database table structure. We need to create migration file and write table structure then migrate that migration. Sometimes we need to rollback that migration. So here we will discuss about the migration rollback in laravel.

We can run the rollback artisan command to rollback on a particular step. We can execute the following artisan command.

php artisan migrate:rollback --step=1

Every time when we will rollback, we will get the last batch of migration.

**Note: **This rollback command will work on laravel 5.3 or above version. For the version below 5.3, there is no command available for migration rollback in laravel.

We can also use the following command to rollback and re migrate.

php artisan migrate:refresh --step=2

It will rollback and remigrate last two migration.

You can also checkout the article for executing single migration by clicking on the link below.

How to migrate single migration in laravel

#laravel #how to perform rollback migration in laravel #laravel migration rollback #migration refresh in laravel #migration rollback batch in laravel #migration rollback for one specific migration #migration rollback in laravel

Seamus  Quitzon

Seamus Quitzon

1595201363

Php how to delete multiple rows through checkbox using ajax in laravel

First thing, we will need a table and i am creating products table for this example. So run the following query to create table.

CREATE TABLE `products` (
 `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
 `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
 `description` varchar(255) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
 `created_at` timestamp NULL DEFAULT CURRENT_TIMESTAMP,
 `updated_at` datetime DEFAULT NULL,
 PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=7 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci

Next, we will need to insert some dummy records in this table that will be deleted.

INSERT INTO `products` (`name`, `description`) VALUES

('Test product 1', 'Product description example1'),

('Test product 2', 'Product description example2'),

('Test product 3', 'Product description example3'),

('Test product 4', 'Product description example4'),

('Test product 5', 'Product description example5');

Now we are redy to create a model corresponding to this products table. Here we will create Product model. So let’s create a model file Product.php file under app directory and put the code below.

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
    protected $fillable = [
        'name','description'
    ];
}

Step 2: Create Route

Now, in this second step we will create some routes to handle the request for this example. So opeen routes/web.php file and copy the routes as given below.

routes/web.php

Route::get('product', 'ProductController@index');
Route::delete('product/{id}', ['as'=>'product.destroy','uses'=>'ProductController@destroy']);
Route::delete('delete-multiple-product', ['as'=>'product.multiple-delete','uses'=>'ProductController@deleteMultiple']);

#laravel #delete multiple rows in laravel using ajax #laravel ajax delete #laravel ajax multiple checkbox delete #laravel delete multiple rows #laravel delete records using ajax #laravel multiple checkbox delete rows #laravel multiple delete

Laravel Eloquent Relationships

In this example we will see Laravel Eloquent relationships, laravel provides many relationship like laravel hasmany, laravel belongsto, wherehas laravel, many to many relationship laravel, eloquent relationships, one to many relationship laravel, one to one relationship laravel, here we will see all relationship with example.

There are 3 types of relationships in laravel:

  • One to one
  • One to many
  • Many to many

Read More : Laravel Eloquent Relationships

https://websolutionstuff.com/post/laravel-eloquent-relationships


You May Also Like :

  1. https://websolutionstuff.com/post/how-to-get-current-url-in-laravel
  2. https://websolutionstuff.com/post/laravel-8-google-pie-chart-example
  3. https://websolutionstuff.com/post/laravel-8-autocomplete-search-from-database

#laravel eloquent relationships #laravel relationship #one to one relationship #laravel hasmany #many to many relationship laravel #one to many relationship laravel

Harish Kumar

Harish Kumar

1591166772

#2 - One To Many relationship | hasMany() | Laravel Eloquent Relationships

https://youtu.be/rb2Tf8zByRU

#laravel #laravel eloquent #laravel eloquent relationships #hasmany