Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing data from form to controller Laravel 5

I'm trying register users in a laravel 5 application using the restful controller.

The problem is that when I dump the data in my store function, I only get the csrf token, but not the values.

Here's what I tried so far:

  • Input::all();
  • Request::get();

Here's the code I'm executing:

Form

<form class="form-horizontal" method="post" action="/users">

<div class="form-group">
    <label for="name" class="col-lg-2 control-label">
        Name
    </label>
    <div class="col-lg-10">
        <input type="text" class="form-control" id="name" value="a">
    </div>
</div>
<div class="form-group">
    <label for="email" class="col-lg-2 control-label">
        Email
    </label>
    <div class="col-lg-10">
        <input type="email" class="form-control" id="email" value="[email protected]">
    </div>
</div>
<div class="form-group">
    <label for="password" class="col-lg-2 control-label">
        Pw
    </label>
    <div class="col-lg-10">
        <input type="password" class="form-control" id="password">
    </div>
</div>
<div class="form-group">
    <div class="col-lg-10 col-lg-offset-2">
        <button type="reset" class="btn btn-default">Cancel</button>
        <button type="submit" class="btn btn-primary">Create</button>

    </div>
</div>
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>

Controller

public function store()
{
    $input = Input::only('name','email','password');            
    $user = new User;
    $user->name = $input['name'];
    $user->email = $input['email'];
    $user->password = Hash::make($input['password']);
    $user->save();
}

And Route is just

Route::resource('users','UsersController');
like image 418
Shayle Avatar asked Dec 09 '22 04:12

Shayle


1 Answers

Your input fields are all missing a name attribute! For example

<input type="text" class="form-control" id="name" name="name" value="a">
<!--                                              ^^^^^^^^^^^        -->
like image 68
lukasgeiter Avatar answered Dec 11 '22 08:12

lukasgeiter