Steve Steve - 6 months ago 18
PHP Question

Fetching individual inputs from form laravel

I am a laravel begineer. I want to fetch the information inputted form the form. the form field names are

name
,
email
and
contact.
which i am trying to fetch just like
$_POST['name'] ,$_POST['email']
in core php

{{form::open(array('route'=>'employees.store'))}}


the controller store() function: this will fetch all the inputs from the form. i want individual inputs.

public function store()
{
$input=Input::all();
employee::create($input)
}

Answer
public function store()
{
  $input = Input::all();
  $e = new Employee();

  $e->name = $input['name'];
  $e->email = $input['email'];
  $e->contact = $input['contact'];
  ...
  $e->save();
}

But shouldn't store() receive a Request object like so?

public function store(Request $request)

Then you could do this

public function store(Request $request)
{
      $input = $request->all();
      $e = new Employee();

      $e->name = $input['name'];
      $e->email = $input['email'];
      $e->contact = $input['contact'];
      ...
      $e->save();
}
Comments