mercredi 21 septembre 2016

Laravel Passing Data from View to Controller

I'm using Laravel 5.3. I'm trying to pass some input from the View to a Controller. Here is what I am doing now in the View:

<form class="form-horizontal" role="form" method="POST" action="">
   
    <input name="_method" type="hidden" value="PUT">
    <div class="form-group">
         <label for="name" class="col-md-4 control-label">Name</label>
         <div class="col-md-6">
             <input id="name" type="text" class="form-control" name="name" value="" required autofocus>

             @if ($errors->has('name'))
             <span class="help-block">
                 <strong></strong>
             </span>
             @endif
        </div>
    </div>
    <div class="form-group">
          <div class="col-md-6 col-md-offset-4">
                <button type="submit" class="btn btn-primary">
                    Register
                </button>
          </div>
    </div>
</form>

And here is the route:

Route::put('/update/company', [
'as' => 'updateCompany',
'uses' => 'Auth\RegisterController@update'
]);

And here is the Controller:

public function update(Request $request){
    $compEmail = $this->companyEmail;
    if( ! $compEmail)
    {
        echo "Email Invalid";
    }

    $user = User::all()->where("email", $compEmail)->first();

    if ( ! $user)
    {
        echo "Invalid Company";
    }

    $user->name = $request->input('name');
    $user->confirmed = 1;
    $user->confirmation_code = null;

    $user->save();

}

This is giving me the error: Creating default object from empty value on the line $user->name = $request->input('name');

Any tips?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire