skip to Main Content

I would like to get HTML data using an interfaced method like a Request. If anyone knows please explain me.

I would like to get output like this one! please help to write a sample Request php interface.

My real scenario is I have a controller that controller has a function Create. create function passed a parameter as a Request class. I want access to HTML input as I mentioned in the question. That is my problem.

<input name="inputname">
<input name="anotherinputname">
public function create(Request $request) {
   echo $request->inputname;
   echo $request->anotherinputname;
}

So please help to make Request class. Thanks

2

Answers


  1. It’s not working as you think.
    Laravel uses dependency injection.
    You can define a Request class and in its constructor, you can map the POST data to properties.
    something like this:

    class Request {
        public $get;
        public $post;
    
        public function __construct() {
            $this->get = $_GET;
            $this->post = $_POST;
        }
    }
    

    and then you can access the POST data this way:

    $request->post['anotherinputname'];
    
    Login or Signup to reply.
  2. Assuming you have this method in your controller:

    public function create(Request $request) {
    

    You should grab your variables by doing:

    $field = $request->get('fieldName');
    dump($field);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search