-5

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.

mahbub
  • 103
  • 1
  • 3
  • 13
  • Does this answer your question? [Laravel get POSTed data using request](https://stackoverflow.com/questions/50925572/laravel-get-posted-data-using-request) – steven7mwesigwa Nov 27 '22 at 07:34
  • [How do I get HTTP Request body content in Laravel?](https://stackoverflow.com/questions/28459172/how-do-i-get-http-request-body-content-in-laravel) – steven7mwesigwa Nov 27 '22 at 07:35
  • [How to get All input of POST in Laravel](https://stackoverflow.com/questions/32718870/how-to-get-all-input-of-post-in-laravel) – steven7mwesigwa Nov 27 '22 at 07:39
  • [Laravel access request object outside controller](https://stackoverflow.com/questions/38319707/laravel-access-request-object-outside-controller) – steven7mwesigwa Nov 27 '22 at 08:48

1 Answers1

1

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());
}
Saroj Shrestha
  • 2,696
  • 4
  • 21
  • 45
  • not in controller. I ask how to get this in model. – mahbub Nov 27 '22 at 06:33
  • Could you share your model where you need data if it is a function, then you have to call that function by passing the data `$request->all()` as params, or are you creating some scope? – Saroj Shrestha Nov 27 '22 at 06:34
  • Model::create($request->input()); but from model how to receive this? parameter does not working here. – mahbub Nov 27 '22 at 06:36
  • Please check my above-updated answer. – Saroj Shrestha Nov 27 '22 at 06:38
  • Every time you think you want to post an answer to a new question, the first thing you should do is take 5 or 10 minutes to search Stack Overflow (via Google search) and hunt aggressively for duplicate pages that already exist. If you find a duplicate that resolves the new question, please vote to close the new question. If you have something unique and valuable to add to the older page, please post your advice there. By ignoring pre-existing content, researchers have a harder time finding and comparing relevant insights on a given topic. – steven7mwesigwa Nov 27 '22 at 07:41
  • @steven7mwesigwa You did not understand my question. I asked for model, not controller. Do you think i came here without searching? Please read carefully first question then answer. – mahbub Nov 27 '22 at 08:40
  • @mahbub Umm, . This question isn't unique by any means. I've already linked a few in the comment section of your question. If you still aren't satisfied, take a look at : [Laravel access request object outside controller](https://stackoverflow.com/questions/38319707/laravel-access-request-object-outside-controller) – steven7mwesigwa Nov 27 '22 at 08:48