Friday, 22 January 2021

How to get data from following and follower in mysql

 

 

Query 1
SELECT
  `connection`.`person_id`,
  `connection`.`follower_id`,
  `people`.`name`,
  `people`.`age`
FROM
  `test`.`people`
  INNER JOIN `test`.`connection`
    ON (
      `people`.`id` = `connection`.`follower_id`
    )
WHERE (`connection`.`person_id` = 3);

Query 2
SELECT person_id, GROUP_CONCAT(DISTINCT follower_id SEPARATOR ', ') AS follower
FROM CONNECTION GROUP BY person_id

Query 3
SELECT person_id, GROUP_CONCAT(DISTINCT follower_id SEPARATOR ', ') AS follower
FROM CONNECTION WHERE (`connection`.`person_id` = 3)
GROUP BY person_id

Query 4
SELECT DISTINCT f.person_id,
o.following,
e.follower
FROM CONNECTION f
LEFT JOIN
(
    SELECT CONNECTION.person_id, GROUP_CONCAT(DISTINCT follower_id SEPARATOR ', ') AS following
    FROM CONNECTION GROUP BY person_id
) AS o ON f.person_id = o.person_id
LEFT JOIN
(
    SELECT CONNECTION.follower_id, GROUP_CONCAT(DISTINCT person_id SEPARATOR ', ') AS follower
    FROM CONNECTION GROUP BY follower_id
) AS e ON f.person_id = e.follower_id

 

Monday, 11 January 2021

Git command

git init
git clone https://github.com/rameshyadavjee/laravel.git
git branch temp
git checkout temp
git add *
git commit –m "Message to go with the commit here"
git config --local user.email rameshyadavjee@gmail.com
git remote add origin https://github.com/rameshyadavjee/laravel.git
git push origin master

 

Run the below code

ssh-keygen
Enter
Enter
Enter

Got to profile and search .ssh   // Example C:\Users\KRISHNA\.ssh

Open the file id_rsa.pub
Copy the content and

https://github.com/settings/keys
Click on New SSH Key
Paste the content

Thats it

How to get last insert id?

 In laravel, when you go with DB query builder then you can use insertGetId() that will insert a record and then return last inserted record id.
Example:
 
        $id = DB::table('users')->insertGetId(
                ['email' => 'rameshyadavjee@gmail.com', 'name' => 'Ramesh']
        );
        print_r($id);
   

If you are inserting a record using Laravel Eloquent then you don't need to use insertGetId() function to get last inserted id. You can simply use create method to insert a new record into. The inserted model instance will be returned to you from the method.
Example:


        $user = User::create(['name'=>'Ramesh','email'=>'rameshyadavjee@gmail.com']);
        print_r($user->id);
 

What is traits?

Traits are a mechanism for code reuse in single inheritance languages such as PHP. Write the same code again, to avoid this use the traits. The traits are used when multiple classes share the same functionality.

Here is an example of trait.

<?php
namespace App\Http\Traits;
use App\Models\Users;

trait UserTrait {
    public function userdata() {
        // Fetch all the user from the 'user' table.
        $user = User::all();
        return $user;
    }
}

************************************************

use App\Http\Traits\UserTrait;

class .....
{
    use UserTrait;
    public function ()
    {
        $data = $this->userdata();
        we will get the data in $data variable.
    }
}


Check if Table/Column Already Exists

Check if Table/Column Already Exists


public function up()
{
  if (!Schema::hasTable('vendor')) {
    Schema::create('vendor', function (Blueprint $table) {
      $table->increments('id');
      $table->string('name');      
      $table->timestamps();
    });
  }
}

public function up()
{
  if (Schema::hasTable('vendor')) {
    Schema::table('vendor', function (Blueprint $table) {
      if (!Schema::hasColumn('vendor', 'address')) {
        $table->string('address');
      }
    });
  }
}

What is Chunk and Cursor?

 What is Chunk and Cursor?

Chunk: It will “paginate” your query, this way you use less memory.
* Uses less memory
* It takes longer
public function getData() {
    Contact::chunk(1000, function ($contacts) {
        foreach ($contacts as $contact) {
            //rest of your code...
        }
    });
}

Cursor: You will use PHP Generators to search your query items one by one.

* It takes less time
* Uses more memory
public function getData() {
    foreach (Contact::cursor() as $contact) {
        //rest of your code...
    }
}

How to enable QueryLog?

use DB;

 DB::connection()->enableQueryLog();

$data_array =  DB::table('vendor')->where('vendor_id', '=', $uid)->get();       

$x = DB::getQuerylog();

dd($x);

Machine Learning - Potato Leaf Disease Prediction

Step 1: import numpy as np import pandas as pd import splitfolders import matplotlib.pyplot as plt import tensorflow as tf from tensorflow i...