Skip to content

Core\Request

Fariz Luqman edited this page Mar 24, 2017 · 2 revisions

Responsible for getting user's Input to the server

Getting user input

Use the method Request::get('variable_name'); to get GET and POST data.

Say that you have the form below:

<form method="POST" action="myform">
   <label>My Name Is:</label>
   <input type="textbox" name="myname"><br>
   <label>My Age Is:</label>
   <input type="textbox" name="myage">
   <input type="submit" value="Submit">
</form>

And say you have your route (in routes/web.php) set to this:

Router::post('myform', 'Controller\Form@getDetails');

On your controller, you can do this:

namespace Controller;

use Core\Response;

class Form {
  public function getDetails()
  {
       echo Response::get('myname');
       echo Response::get('myage');
  }
}

Getting Flash Messages set by Core\Response

Say you have redirected with a message

Response::redirect('login')->with(['message'=>'Login failed']);

You can get the variable message by doing this

echo Request::get('message');

Visit our website for tutorials: stupidlysimple.github.io

Clone this wiki locally