mercredi 27 juin 2018

Updating user data in default Laravel application

I just started using Laravel and I can't get my head around this problem... I hope more experienced people here can spot the error I'm making.

I configured a fresh laravel application and performed

php artisan make:auth

Following the instructions from https://laravel.com/docs/5.6/authentication#authentication-quickstart.

Next, I created these routes in routes/web.php:

Route::get('/user', ['as'=>"user", 'uses'=>'UserController@show']);
Route::post('/user/update', ['as' => 'user.update', 'uses' => 'UserController@update']);

This is my UserController.php:

<?php

namespace App\Http\Controllers;
use Auth;
use Illuminate\Http\Request;
use App\User;

class UserController extends Controller
{
  public function show() {

    return view('user')->withUser(Auth::user());
  }
  public function update(Request $request)
    {
        $user = Auth::user();
        $user->name=$request->input('name');
        $user->email=$request->input('email');

        $user->save();
        return Redirect::route('user');
    }
}

And this is the form in my user.blade.php:

{!! Form::model($user,['action' => ['UserController@update'], 'method' => 'POST']) !!}
<tr><th colspan=2>My user data</th></tr>
  <tr>
      <td>Name</td>
      <td>{!! Form::text('name', null, ['class' => 'form-control']) !!}</td>
  </tr>
  <tr>
      <td>E-mail Address</td>
      <td>{!! Form::text('email', null, ['class' => 'form-control']) !!}</td>
  </tr>
  <tr><td colspan=2>{!! Form::submit('Submit', ['class' => 'btn btn-primary']) !!}</td></tr>

{!! Form::close() !!}

Nothing seems to happen when I click the submit button in the form... Data is not changed in the database.



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2tH8dOA
via IFTTT

Aucun commentaire:

Enregistrer un commentaire