Tuesday, 9 February 2021

Guzzle Http Client Request

 composer require guzzlehttp/guzzle

GET REQUEST

public function getGuzzleRequest()
{
    $client = new \GuzzleHttp\Client();
    $request = $client->get('http://example.com');
    $response = $request->getBody();
   
    dd($response);
}


POST REQUEST

public function postGuzzleRequest()
{
    $client = new \GuzzleHttp\Client();
    $url = "http://example.com/api/posts";
   
    $data['name'] = "codechief";
    $request = $client->post($url,  ['body'=>$data]);
    $response = $request->send();
 
    dd($response);
}


PUT REQUEST

public function putGuzzleRequest()
{
    $client = new \GuzzleHttp\Client();
    $url = "http://example.com/api/posts/1";
    $data['name'] = "codechief";
    $request = $client->put($url,  ['body'=>$data]);
    $response = $request->send();
   
    dd($response);
}


DELETE REQUEST

public function deleteGuzzleRequest()
{
    $client = new \GuzzleHttp\Client();
    $url = "http://example.com/api/posts/1";
    $request = $client->delete($url);
    $response = $request->send();
 
    dd($response);
}

How to create and destroy cookie

Set cookie: Cookie::queue(Cookie::make('cookieName', 'value', $minutes));

Get cookie: $value = $request->cookie('cookieName'); or $value = Cookie::get('cookieName');

Forget/remove cookie: Cookie::queue(Cookie::forget('cookieName'));

Check if cookie exist: Cookie::has('cookiename'); or $request->hasCookie('cookiename') will return true or false

Sessions knowledge

 Set session variable in laravel

public function xxxxxx(Request $request, $id)  {
           
    $request->session()->put('key', 'value');

 }

Get session value in laravel

$value = $request->session()->get('key');

Retrieving all data from the session

$data = $request->session()->all();

Checking if An Item Exists In The Session

if ($request->session()->has('users')) {
  //
 }

Destroying session in Laravel

public function showProfile(Request $request, $id) {      
     //Deleting Items From The Session
     $request->session()->forget('key');
     $request->session()->flush();    
 }

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...