Home  >  Q&A  >  body text

Retrieve HTML input values ​​using an interface (like Laravel)

I want to use interface methods like request to get HTML data. If anyone knows please explain.

I want to get output like this! Please help in writing a sample Request php interface.

My real scenario is that I have a controller that has a create function. The create function passes parameters as Request class. I want to access the HTML input as I mentioned in the question. This is my problem.

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

So please help make the Request class. Thanks

P粉514001887P粉514001887226 days ago392

reply all(1)I'll reply

  • P粉985686557

    P粉9856865572024-03-31 10:54:21

    It doesn't work like you think. Laravel uses dependency injection. You can define a Request class and map POST data to properties in its constructor. Something like this:

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

    You can then access the POST data via:

    $request->post['anotherinputname'];

    reply
    0
  • Cancelreply