Issue
I'm new in laravel and I'm working on a project and I want to create users with a profile for each of one but I can't find a tutorial for that to insert data from blade to table and show data from table to the user's profile. would you please recommend to me a tutorial I can follow their steps.
Solution
I have simple way to update user profile, and in this case just name and email.
- create new controller, any name
public function index()
{
return view('usersprofile.index');
}
public function update(Request $request, $id) {
$user = User::findOrFail($id);
$user->name = $request->get('name');
$user->email = $request->get('email');
$user->save();
return redirect('users')->with('status', 'Profile updated!');
}
- create folder usersprofile inside resource->view, and create index.blade.php
<form method="POST" action="{{ route('users.update', Auth::user()->id) }}">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<input type="hidden" name="_method" value="PUT">
<div class="form-group">
<label for="name">Name</label>
<input type="text" name="name" value="{{ Auth::user()->name }}" class="form-control">
</div>
<div class="form-group">
<label for="email">Email</label>
<input type="email" name="email" value="{{ Auth::user()->email }}" class="form-control">
</div>
<button type="submit" class="btn btn-primary">
<i class="fa fa-btn fa-sign-in"></i>Update
</button>
</form>
- edit your route file.
Route::resource('users', 'YourController');
and you need to add Use App\User;
Answered By - Elonelon
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.