I have recently started working in Laravel, my first Framework
. I have experience with PHP
but I am a little lost now.
I used the default auth
that comes with laravel. But I am trying to make a function to edit the users that have registered.
I dont quite see how the data gets to the database from the form.
My form: (didn't put all inputs)
@isset($user)
<form method="POST" action="{{ WHAT GOES HERE?? }}">
@csrf
{{--name--}}
<div class="form-group row">
<label for="name" class="col-md-4 col-form-label text-md-right">{{ __('Name') }}</label>
<div class="col-md-6">
<input id="name" type="text" class="form-control{{ $errors->has('name') ? ' is-invalid' : '' }}" name="name" value="{{ $user->name }}" required autofocus>
</div>
</div>
{--last name--}}
<div class="form-group row">
<label for="lastname"
class="col-md-4 col-form-label text-md-right">{{ __('Last Name') }}</label>
<div class="col-md-6">
<input id="lastname" type="text"
class="form-control{{ $errors->has('lastname') ? ' is-invalid' : '' }}" name="lastname" value="{{ $user->lastname }}" required autofocus>
</div>
</div>
<div class="form-group row mb-0">
<div class="col-md-6 offset-md-4">
<button type="submit" class="btn btn-primary">
{{ __('Edit user') }}
</button>
</div>
</div>
I did not make a route yet, as I do not know how exactly. Or if this is even needed.
My controller:
public function edit_profile($userId, Request $request)
{
$this->isAllowed($userId, true);
$userProfile = User::findOrFail((int)$userId);
//TODO validation
//TODO update user model + save to db
$userProfile->update();
return view('user/edit_profile', [
/* $ */
'user' => $userProfile,
]);
}
As stated; I do know what needs to happen. I just don't know and understand how.
And last, my user.php
protected $fillable = [
'name',
'lastname',
'email',
'password',
'mobile_number',
'date_of_birth',
];
My next step would be to make a route, to get the data to the controller. But I don't see how this route would look.