Laravel date_format Validation Example

Laravel date_format Validation Example
Hi Guys,

In this tutorial I will show laravel Date Format Validation example You can validate date_format validation rules. With date_format:format method you can set the preferred date format, and the filed value must match the given format.

The field under validation must match the given format. You should use either date_format when validating a field, not both. This validation rule supports all formats supported by PHP's Date class.

Example
/**
 * Show the application dashboard.
 *
 * @return \Illuminate\Contracts\Support\Renderable
 */
public function store(Request $request)
{
    $request->validate([
        'start_date' => 'date_format:d/m/Y',
        'end_date' => 'date_format:d/m/Y'
    ]);
}
OR
/**
 * Show the application dashboard.
 *
 * @return \Illuminate\Contracts\Support\Renderable
 */
public function store(Request $request)
{
  $request->validate([
      'start_date' => 'date_format:Y-m-d',
      'end_date' => 'date_format:Y-m-d'
  ]);
}

It will help you ...

Laravel Guzzle Request Example

Laravel Guzzle Request Example

Hi Guys

Today, I will explain how to use laravel guzzle http client request? we will show example of guzzle http client request in laravel. we will guide you how to use guzzle http client GET and POST request with php laravel.

I will use guzzlehttp/guzzle composer package for guzzle http request in laravel application.we will install the guzzlehttp/guzzle package in laravel.

A Guzzle is a PHP HTTP client that makes it easy to send HTTP requests with data, headers and trivial to integrate with web services. Guzzle is a simple interface for building query strings, POST requests, streaming large uploads, streaming large downloads, using HTTP cookies, uploading JSON data, etc.

Here following the step and you can get simple example of guzzle.

Install Guzzle Package

In this step, we will install guzzlehttp/guzzle package and then we can easily use thir method So let's just run bellow command.

composer require guzzlehttp/guzzle
Example of Requests Using Guzzle:

Here this step, I will show you how to run all above listed request you can use following controller method:

GET Request:
/**
 * Show the application dashboard.
 *
 * @return \Illuminate\Contracts\Support\Renderable
 */
public function guzzleGetRequest()
{
    $client = new \GuzzleHttp\Client();
    $request = $client->get('http://ourexample.com');
    $response = $request->getBody();
   
    dd($response);
}
Post Request:
/**
 * Show the application dashboard.
 *
 * @return \Illuminate\Contracts\Support\Renderable
 */
public function guzzlePostRequest()
{
    $client = new \GuzzleHttp\Client();
    $url = "http://ourexample.com/api/blog";
   
    $myBody['name'] = "Demo";
    $request = $client->post($url,  ['body'=>$myBody]);
    $response = $request->send();
  
}
Put Request:
/**
 * Show the application dashboard.
 *
 * @return \Illuminate\Contracts\Support\Renderable
 */
public function guzzlePutRequest()
{
    $client = new \GuzzleHttp\Client();
    $url = "http://ourexample.com/api/blog/1";
    $myBody['name'] = "Demo";
    $request = $client->put($url,  ['body'=>$myBody]);
    $response = $request->send();
   
    dd($response);
}
Delete Request:
/**
 * Show the application dashboard.
 *
 * @return \Illuminate\Contracts\Support\Renderable
 */
public function guzzleDeleteRequest()
{
    $client = new \GuzzleHttp\Client();
    $url = "http://ourexample.com/api/blog/1";
    $request = $client->delete($url);
    $response = $request->send();

    dd($response);
}

It will help you...

Laravel Get Headers From Request Example

laravel get headers from request

Hi Dev,

In this blog ,I Will learn you how to get header in laravel. I will show example of laravel get headers from request you can easliy laravel get all headers from request. I will explain laravel get all headers.

I can blow you can easily get headers from request in laravel this example.

Exmaple:1

Here In this exmaple laravel Get headers from request to a header method

/**
 * Show the application dashboard.
 *
 * @return \Illuminate\Contracts\Support\Renderable
 */
public function index(Request $request)
{
    $headers = $request->header('connection');

    dd($headers);
}
Output :
"keep-alive"
Exmaple:2

Here In this exmaple laravel get headers from request using a request builder to a header method

/**
 * Show the application dashboard.
 *
 * @return \Illuminate\Contracts\Support\Renderable
 */
public function index()
{
    $headers = \Request::header();

   dd($headers);
}
Output :
array:13 [
  "host" => array:1 [
    0 => "localhost:8000"
  ]
  "connection" => array:1 [
    0 => "keep-alive"
  ]
  "cache-control" => array:1 [
    0 => "max-age=0"
  ]
  "upgrade-insecure-requests" => array:1 [
    0 => "1"
  ]
  "user-agent" => array:1 [
    0 => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"
  ]
  "sec-fetch-user" => array:1 [
    0 => "?1"
  ]
  "accept" => array:1 []
  "sec-fetch-site" => array:1 [
    0 => "same-origin"
  ]
  "sec-fetch-mode" => array:1 [
    0 => "navigate"
  ]
  "referer" => array:1 []
  "accept-encoding" => array:1 [
    0 => "gzip, deflate, br"
  ]
  "accept-language" => array:1 [
    0 => "en-US,en;q=0.9,la;q=0.8,gu;q=0.7"
  ]
  "cookie" => array:1 [
    0 => "_ga=GA1.1.2099257977.1573906086; __gads=Test; _gid=GA1.1.879789242.1575463476; __atuvc=13%7C46%2C68%7C47%2C5%7C48%2C17%7C49; XSRF-TOKEN=eyJpdiI6IlRZVE1VUnh2WFNu "
  ]
]
Exmaple:3

Here In this exmaple laravel Get headers from request to a getallheaders method

/**
 * Show the application dashboard.
 *
 * @return \Illuminate\Contracts\Support\Renderable
 */
public function index()
{
   $headers = getallheaders();

   dd($headers);
}
Output :
array:13 [
  "Host" => "localhost:8000"
  "Connection" => "keep-alive"
  "Cache-Control" => "max-age=0"
  "Upgrade-Insecure-Requests" => "1"
  "User-Agent" => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"
  "Sec-Fetch-User" => "?1"
  "Accept" => "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3"
  "Sec-Fetch-Site" => "same-origin"
  "Sec-Fetch-Mode" => "navigate"
  "Referer" => "http://localhost:8000/login"
  "Accept-Encoding" => "gzip, deflate, br"
  "Accept-Language" => "en-US,en;q=0.9,la;q=0.8,gu;q=0.7"
  "Cookie" => "_ga=GA1.1.2099257977.1573906086; __gads=Test; _gid=GA1.1.879789242.1575463476; __atuvc=13%7C46%2C68%7C47%2C5%7C48%2C17%7C49; XSRF-TOKEN=eyJpdiI6IlRZVE1VUnh2WFNu "
]
Exmaple:4

Here In this exmaple laravel Get headers from request to a apache_request_headers method

/**
 * Show the application dashboard.
 *
 * @return \Illuminate\Contracts\Support\Renderable
 */
public function index()
{
   $headers = apache_request_headers();

   dd($headers);
}
Output :
array:13 [
  "Host" => "localhost:8000"
  "Connection" => "keep-alive"
  "Cache-Control" => "max-age=0"
  "Upgrade-Insecure-Requests" => "1"
  "User-Agent" => "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36"
  "Sec-Fetch-User" => "?1"
  "Accept" => "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3"
  "Sec-Fetch-Site" => "same-origin"
  "Sec-Fetch-Mode" => "navigate"
  "Referer" => "http://localhost:8000/login"
  "Accept-Encoding" => "gzip, deflate, br"
  "Accept-Language" => "en-US,en;q=0.9,la;q=0.8,gu;q=0.7"
  "Cookie" => "_ga=GA1.1.2099257977.1573906086; __gads=Test; _gid=GA1.1.879789242.1575463476; __atuvc=13%7C46%2C68%7C47%2C5%7C48%2C17%7C49; XSRF-TOKEN=eyJpdiI6IlRZVE1VUnh2WFNu "
]

it will help you....