Page tree
Skip to end of metadata
Go to start of metadata

Description


Core\Request request()


Using our request() function will give you access to our core request class, which is used to handle incoming HTTP requests.

Examples


<?php

route('/foo', function() {

   /**
    * URL Example: /foo?hello=1
    */
   if (request()->get('hello')) {
      echo "Hello!";
   }

   // Checks if a form has been posted
   if (request()->isPost()) {

   }

   /**
    * URL Example: /foo/bar
    */
   echo request()->segment(1); // Prints foo
   echo request()->segment(2); // Prints bar

});

Methods


MethodDescriptionUsageReturns

get(string $var)

 


$var

Provide the HTTP request key

Returns the HTTP request value.

/**
 * URL Example: /foo?hello=1
 */
if (request()->get('hello')) {
   echo "Hello!";
}

HTTP request value on success, null on failure.

This supports all incoming HTTP
requests (e.g. GET, POST, DELETE etc...) 

isPost()

Checks to see if a form has been posted.

if (request()->isPost()) {

}

true on success, false on failure.

This method only checks POST requests.

segment(int $number)

 


$number

Provide the segment number
of the URL. 

Returns URL segment based on the
forward slash. 

 

/**
 * URL Example: /foo/bar
 */
echo request()->segment(1); // Prints foo
echo request()->segment(2); // Prints bar
Segment value on success, null on failure.
  • No labels