Home > Back-end >  how to get form $request all data in laravel model
how to get form $request all data in laravel model

Time:11-27

This is learning purpose question.

I have a form and after submit the form i want to catch this form all request data into the model. so how to do this?

thanks.

CodePudding user response:

On the controller you could do something like this:

public function postData(Request $request)
{
  dd($request->all()); //this will print data

  //in case you want to insert to the database:
  // also you have to import the User model at the top with `use App\Models\User;`
  User::create([
     'name' => $request->input('name),
     'email' => $request->input('email)
  ])
}

This is an example of a user Model you could use with your own model.

Update: let's say you want to get data on the User model function createUser.

Model User.php

public static function createUser($data)
{
  dd($data);
}

And on controller:

public function store(Request $request)
{
  User::createUser($request->all());
}

CodePudding user response:

I have an answer: using "$_REQUEST" i can get the form request all data into model.

dd($_REQUEST);
  • Related