简体   繁体   中英

laravel dont update user profile

I am trying to make so that the user can change his profile

home.blade.php


@section('content')
           <!-- Main content -->
           <section class="content">
               <div class="container">
                   <div class="row">
                       <div class="col-md-3">

                           <!-- Profile Image -->
                           <div class="card card-primary card-outline">
                               <div class="card-body box-profile">
                                   <div class="text-center">
                                       <img class="profile-user-img img-fluid img-circle" src="{{asset('/images/profile.png')}}" alt="User profile picture">
                                   </div>

                                   <h3 class="profile-username text-center">{{auth()->user()->name}}</h3>

                                   <p class="text-muted text-center">{{auth()->user()->email}}</p>

                                   <ul class="list-group list-group-unbordered mb-3">
                                       <li class="list-group-item">
                                           <b>Followers</b> <a class="float-right">1,322</a>
                                       </li>
                                       <li class="list-group-item">
                                           <b>Following</b> <a class="float-right">543</a>
                                       </li>
                                       <li class="list-group-item">
                                           <b>Friends</b> <a class="float-right">13,287</a>
                                       </li>
                                   </ul>

                                   <a href="#" class="btn btn-primary btn-block"><b>Follow</b></a>
                               </div>
                               <!-- /.card-body -->
                           </div>
                           <!-- /.card -->

                           <!-- About Me Box -->
                           <div class="card card-primary">
                               <div class="card-header">
                                   <h3 class="card-title">About Me</h3>
                               </div>
                               <!-- /.card-header -->
                               <div class="card-body">
                                   <strong><i class="fas fa-book mr-1"></i> Education</strong>

                                   <p class="text-muted">
                                       B.S. in Computer Science from the University of Tennessee at Knoxville
                                   </p>

                                   <hr>

                                   <strong><i class="fas fa-map-marker-alt mr-1"></i> Location</strong>

                                   <p class="text-muted">Malibu, California</p>

                                   <hr>

                                   <strong><i class="fas fa-pencil-alt mr-1"></i> Skills</strong>

                                   <p class="text-muted">
                                       <span class="tag tag-danger">UI Design</span>
                                       <span class="tag tag-success">Coding</span>
                                       <span class="tag tag-info">Javascript</span>
                                       <span class="tag tag-warning">PHP</span>
                                       <span class="tag tag-primary">Node.js</span>
                                   </p>

                                   <hr>

                                   <strong><i class="far fa-file-alt mr-1"></i> Notes</strong>

                                   <p class="text-muted">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam fermentum enim neque.</p>
                               </div>
                               <!-- /.card-body -->
                           </div>
                           <!-- /.card -->
                       </div>
                       <!-- /.col -->






                       <div class="col-md-9">






                           <div class="card">
                               <div class="card-header p-2">
                                   <ul class="nav nav-pills">
                                       <li class="nav-item"><a class="nav-link active" href="#activity" data-toggle="tab">Activity</a></li>
                                       <li class="nav-item"><a class="nav-link" href="#timeline" data-toggle="tab">Timeline</a></li>
                                       <li class="nav-item"><a class="nav-link" href="#settings" data-toggle="tab">Settings</a></li>
                                   </ul>
                               </div><!-- /.card-header -->
                               <div class="card-body">
                                   <div class="tab-content">
                                       <div class="active tab-pane" id="activity">










                                           <!-- Post -->
                                           <div class="post">
                                               <div class="user-block">
                                                   <img class="img-circle img-bordered-sm" src="../../dist/img/user1-128x128.jpg" alt="user image">
                                                   <span class="username">
                                                       <a href="#">Jonathan Burke Jr.</a>
                                                       <a href="#" class="float-right btn-tool"><i class="fas fa-times"></i></a>
                                                   </span>
                                                   <span class="description">Shared publicly - 7:30 PM today</span>
                                               </div>
                                               <!-- /.user-block -->
                                               <p>
                                                   Lorem ipsum represents a long-held tradition for designers,
                                                   typographers and the like. Some people hate it and argue for
                                                   its demise, but others ignore the hate as they create awesome
                                                   tools to help create filler text for everyone from bacon lovers
                                                   to Charlie Sheen fans.
                                               </p>

                                               <p>
                                                   <a href="#" class="link-black text-sm mr-2"><i class="fas fa-share mr-1"></i> Share</a>
                                                   <a href="#" class="link-black text-sm"><i class="far fa-thumbs-up mr-1"></i> Like</a>
                                                   <span class="float-right">
                                                       <a href="#" class="link-black text-sm">
                                                           <i class="far fa-comments mr-1"></i> Comments (5)
                                                       </a>
                                                   </span>
                                               </p>

                                               <input class="form-control form-control-sm" type="text" placeholder="Type a comment">
                                           </div>
                                           <!-- /.post -->




                                           <!-- Post -->
                                           <div class="post clearfix">
                                               <div class="user-block">
                                                   <img class="img-circle img-bordered-sm" src="../../dist/img/user7-128x128.jpg" alt="User Image">
                                                   <span class="username">
                                                       <a href="#">Sarah Ross</a>
                                                       <a href="#" class="float-right btn-tool"><i class="fas fa-times"></i></a>
                                                   </span>
                                                   <span class="description">Sent you a message - 3 days ago</span>
                                               </div>
                                               <!-- /.user-block -->
                                               <p>
                                                   Lorem ipsum represents a long-held tradition for designers,
                                                   typographers and the like. Some people hate it and argue for
                                                   its demise, but others ignore the hate as they create awesome
                                                   tools to help create filler text for everyone from bacon lovers
                                                   to Charlie Sheen fans.
                                               </p>

                                               <form class="form-horizontal">
                                                   <div class="input-group input-group-sm mb-0">
                                                       <input class="form-control form-control-sm" placeholder="Response">
                                                       <div class="input-group-append">
                                                           <button type="submit" class="btn btn-danger">Send</button>
                                                       </div>
                                                   </div>
                                               </form>
                                           </div>
                                           <!-- /.post -->


                                       </div>










                                       <!-- /.tab-pane -->
                                       <div class="tab-pane" id="timeline">


                                       </div>
                                       <!-- /.tab-pane -->

                                       <div class="tab-pane" id="settings">


                                           <form class="form-horizontal" action="{{route('user.update', auth()->id())}}" method="POST">
                                           @csrf
                                               <div class="form-group row">
                                                   <label for="inputName" class="col-sm-2 col-form-label">Name</label>
                                                   <div class="col-sm-10">
                                                       <input type="name" class="form-control" value="{{auth()->user()->name}}" id="inputName" placeholder="Name">
                                                   </div>
                                               </div>
                                               <div class="form-group row">
                                                   <label for="inputEmail" class="col-sm-2 col-form-label">Email</label>
                                                   <div class="col-sm-10">
                                                       <input type="email" class="form-control" value="{{auth()->user()->email}}" id="inputEmail" placeholder="Email">
                                                   </div>
                                               </div>

                                               <div class="form-group row">
                                                   <label for="inputExperience" class="col-sm-2 col-form-label">Experience</label>
                                                   <div class="col-sm-10">
                                                       <textarea class="form-control" value="{{auth()->user()->edcuation}}" name="education" id="inputExperience" placeholder="Experience"></textarea>
                                                   </div>
                                               </div>
                                               <div class="form-group row">
                                                   <label for="inputSkills" class="col-sm-2 col-form-label">Skills</label>
                                                   <div class="col-sm-10">
                                                       <input type="text" class="form-control" value="{{auth()->user()->skills}}" name="skills" id="inputSkills" placeholder="Skills">
                                                   </div>
                                               </div>
                                               <div class="form-group row">
                                                   <div class="offset-sm-2 col-sm-10">
                                                       <div class="checkbox">
                                                           <label>
                                                               <input type="checkbox"> I agree to the <a href="#">terms and conditions</a>
                                                           </label>
                                                       </div>
                                                   </div>
                                               </div>
                                               <div class="form-group row">
                                                   <div class="offset-sm-2 col-sm-10">
                                                       <button type="submit" class="btn btn-danger">Submit</button>
                                                   </div>
                                               </div>
                                           </form>
                                       </div>
                                       <!-- /.tab-pane -->
                                   </div>
                                   <!-- /.tab-content -->
                               </div><!-- /.card-body -->
                           </div>
                           <!-- /.card -->
                       </div>
                       <!-- /.col -->
                   </div>
                   <!-- /.row -->
               </div><!-- /.container-fluid -->
           </section>
           <!-- /.content -->
@endsection

Usercontroller.php


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\User;

class UserController extends Controller
{
    public function update(Request $request, $id)
    {
        $input = $request->all();
        $user = User::find($id);
        $user->fill($input)->save();
        toastr()->success('Your details have been updated successfully!');
        return back();
    }
}

table


use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateUsersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('users', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('education')->nullable();
            $table->string('address')->nullable();
            $table->boolean('is_admin')->default(0);
            $table->text('skills')->nullable();
            $table->boolean('is_deleted')->default(0);
            $table->boolean('is_verified')->default(0);
            $table->boolean('is_banned')->default(0);
            $table->integer('rank')->default(0);         
            $table->string('email')->unique();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('users');
    }
}

User.php


namespace App\Models;

use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;

class User extends Authenticatable
{
    use HasApiTokens, HasFactory, Notifiable;
    use \HighIdeas\UsersOnline\Traits\UsersOnlineTrait;

    /**
     * The attributes that are mass assignable.
     *
     * @var string[]
     */
    protected $fillable = [
        'name',
        'email',
        'password',
        'skills',
        'education',
    ];

    /**
     * The attributes that should be hidden for serialization.
     *
     * @var array
     */
    protected $hidden = [
        'password',
        'remember_token',
    ];

    /**
     * The attributes that should be cast.
     *
     * @var array
     */
    protected $casts = [
        'email_verified_at' => 'datetime',
    ];

    public function topics()
    {
        return $this->hasMany('App\Models\Discussion');
    }

    public function replies()
    {
        return $this->hasMany('App\Models\DiscussionReply');
    }
}

But I don't know why it doesn't change the data. The message in green that the data has been changed appears but nothing happens, it's been 1 day I'm trying to understand. Sorry for the question, she is a bit stupid but I am an apprentice, if possible give me an explanation with the answer to the problem so that I can do it alone next time.

Update your controller Code $user->update($input); and use Route::put method

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\User;

class UserController extends Controller
{
    public function update(Request $request, $id)
    {
        $input = $request->all();
        $user = User::find($id);
        $user->update($input);
        toastr()->success('Your details have been updated successfully!');
        return back();
    }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM