0

I have a route that is meant to be a post request, and within the controller I want to know what values I send in the post request, I'm new to Laravel. How can I do this?

This is the code for my model:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class OMeta extends Model
{
    protected $fillable= ['n_bandera','h_entrada','h_salida','locacion','fecha','ticket','so'];
}

And I want to get the 'n_bandera' attribute from the post request. How could I do it in the following controller function:

public function store(Request $request){
    // get the 'n_bandera' attribute from the $request

}

Also, I don't want to use methods like all() since I want the content from the request to go to different tables in a database.

Joshua
  • 5,032
  • 2
  • 29
  • 45
saarboledaz
  • 47
  • 2
  • 9
  • Possible duplicate of [How to retrieve a url parameter from request in Laravel 5?](https://stackoverflow.com/questions/38741084/how-to-retrieve-a-url-parameter-from-request-in-laravel-5) – SanSolo Dec 12 '18 at 04:24

5 Answers5

3

Simply you have to retrieve form data in a controller method from different way:

if your form field name is n_bandera then the controller method should like this

use Illuminate\Http\Request;
public function store(Request $request){
  $n_bandera = $request->get('n_bandera'); //use get method in request object 
  OR 
 $n_bandera = $request->input('n_bandera'); //use input method in request object
  OR 
 $n_bandera = $request->n_bandera;   //use dynamic property 
}
Kumar Subedi
  • 334
  • 3
  • 8
1
public function store(Request $request) {
    /* your form needs to have an input field name as n_bandera*/
    $n_bandera = $request->n_bandera;
}
Prashant Pokhriyal
  • 3,727
  • 4
  • 28
  • 40
1
public function store(Request $request){
     $requestData = $request->all();
     $n_bandera = $requestData['n_bandera'];

  /* your form input field name */


} 

I hope it will be helpful for you

1
public function store(Request $request){
    //get the 'n_bandera' attribute from the $request
    $n_bandera = $request->get('n_bandera');
}
Inzamam Idrees
  • 1,955
  • 14
  • 28
0

Instead of $request->all(), for that purpose you can use request->only() , like that:

ModelOne::create($request->only('model_one_param_one'));
ModelTwo::create($request->only('model_two_param_one','model_two_param_two));
jb997
  • 13
  • 2