PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Wednesday, January 19, 2022

[FIXED] laravel 5.8 - create & update user's profile

 January 19, 2022     eloquent, laravel-5     No comments   

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.

  1. 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!');
    }
  1. 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>
  1. edit your route file.
Route::resource('users', 'YourController');

and you need to add Use App\User;



Answered By - Elonelon
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing