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.
These are all routes in routes/web.php:
Route::get('/', 'HomeController@show');
Route::get('/user', ['as'=>"user", 'uses'=>'UserController@show']);
Route::post('/user/update', ['as' => 'user.update', 'uses' => 'UserController@update']);
Auth::routes();
Route::get('/home', 'HomeController@index')->name('home');
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, ['route' => ['user.update'], 'method' => 'POST']) !!}
<tr><th colspan=2>My 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.
Updates:
The controller doesn't get triggered. I added
dd()to theupdate()function and this doesn't yield anything.I tried
composer du, clearing the browser cache and tried another browser. I refreshed the migration usingphp artisan migrate:freshand registered again. Same problem still. debug is set to true, I get other errors if I change things. I added the project to a github repo: github.com/EsthervdS/LaravelTestI reinstalled a whole new project and the problem occurs again.