Cara update profile dan terubah di database

Saya sedang membuat update profile tetapi ketika di simpan tidak berubah, bagaimana caranya agar bisa berubah ya?

web.php

Route::middleware(['auth'])->group(function () {
Route::get('/profile', 'profileController@index')->name('profile');
    Route::post('profile/{user}','profileController@update')->name('profile.update');
  });

controller

public function update( $user, Request $request)
{

        $user->update([
            'name' => $request->username,
            'email' => $request->email,

            dd($request->username)

        ]);

        return redirect('profile')->with('success','Profile updated successfully!');
}

blade

@extends('Template.beranda')
@section('title', 'Dashboard')

@section('content')

 <div class="page-heading">
                <div class="page-title">
                    <div class="row">
                        <div class="col-12 col-md-6 order-md-1 order-last">
                          <h2>Profile</h2><br>
                        </div>
                    </div>
                </div>

                <section id="basic-horizontal-layouts">
                    <div class="row match-height">
                        <div class="col-md-6 col-12">
                            <div class="card">
                                <div class="card-header">
                                    <i class="fa fa-user" style="float:left;">&emsp;</i> <h4 class="card-title">Edit Profile</h4>
                                </div>
                                <div class="card-content">
                                    <div class="card-body">
                                        <form class="form form-horizontal">
                                            <form enctype="multipart/form-data" method="POST" action="{{ route('profile.update',auth()->id()) }}" >
                                                {{ csrf_field() }}
                                            <div class="form-body">
                                                <div class="row">
                                                    <div class="col-md-4">
                                                        <label>Name</label>
                                                    </div>
                                                    <div class="col-md-8">
                                                        <div class="form-group has-icon-left">
                                                            <div class="position-relative">
                                                                <input type="text" class="form-control"
                                                                    placeholder="" id="nama"  name="nama" value="{{ auth()->user()->username }}">
                                                                <div class="form-control-icon">
                                                                    <i class="bi bi-person"></i>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="col-md-4">
                                                        <label>Email</label>
                                                    </div>
                                                    <div class="col-md-8">
                                                        <div class="form-group has-icon-left">
                                                            <div class="position-relative">
                                                                <input type="email" class="form-control"
                                                                    placeholder="Email"  id="email"  name="email" value="{{ auth()->user()->email }}">
                                                                <div class="form-control-icon">
                                                                    <i class="bi bi-envelope"></i>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="col-sm-12 d-flex justify-content-end">
                                                        <button type="submit" class="btn btn-primary me-1 mb-1">Submit</button>
                                                        <button type="reset"
                                                            class="btn btn-light-secondary me-1 mb-1">Reset</button>
                                                    </div>
                                                </div>
                                            </div>
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="col-md-6 col-12">
                            <div class="card">
                                <div class="card-header">
                                    <i class="fa fa-lock" style="float:left;">&emsp;</i> <h4 class="card-title">Ubah Password</h4>
                                </div>
                                <div class="card-content">
                                    <div class="card-body">
                                        <form class="form form-horizontal">
                                            <div class="form-body">
                                                <div class="row">
                                                    <div class="col-md-4">
                                                        <label>Password Lama</label>
                                                    </div>
                                                    <div class="col-md-8">
                                                        <div class="form-group has-icon-left">
                                                            <div class="position-relative">
                                                                <input type="password" class="form-control"
                                                                    placeholder="Password">
                                                                <div class="form-control-icon">
                                                                    <i class="bi bi-lock"></i>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="col-md-4">
                                                        <label>Password Baru</label>
                                                    </div>
                                                    <div class="col-md-8">
                                                        <div class="form-group has-icon-left">
                                                            <div class="position-relative">
                                                                <input type="password" class="form-control"
                                                                    placeholder="Password">
                                                                <div class="form-control-icon">
                                                                    <i class="bi bi-lock"></i>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="col-md-4">
                                                        <label>Konfirmasi Password</label>
                                                    </div>
                                                    <div class="col-md-8">
                                                        <div class="form-group has-icon-left">
                                                            <div class="position-relative">
                                                                <input type="password" class="form-control"
                                                                    placeholder="Password">
                                                                <div class="form-control-icon">
                                                                    <i class="bi bi-lock"></i>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </div>
                                                    <div class="col-12 d-flex justify-content-end">
                                                        <button type="submit"
                                                            class="btn btn-primary me-1 mb-1">Submit</button>
                                                        <button type="reset"
                                                            class="btn btn-light-secondary me-1 mb-1">Reset</button>
                                                    </div>
                                                </div>
                                            </div>
                                        </form>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </section>
                <!-- // Basic Horizontal form layout section end -->
@endsection
avatar chrrriann
@chrrriann

15 Kontribusi 2 Poin

Diperbarui 1 tahun yang lalu

1 Jawaban:

<div>asumsikan $user adalah user id nya... kamu harus query dulu ke database data mana yang mau diupdate<br><br>$userData = TableUserKamu::where('id', $user)-&gt;first();<br><br></div><pre>$userData-&gt;update([ 'name' =&gt; $request-&gt;username, 'email' =&gt; $request-&gt;email,

        dd($request-&amp;gt;username)

    ]);&lt;/pre&gt;&lt;div&gt;semoga membantu&lt;/div&gt;
avatar neurolinker
@neurolinker

2 Kontribusi 0 Poin

Dipost 1 tahun yang lalu

Tanggapan

tabel usernya yang di database kan? tapi merah jadinya

merah gimana ya. itu $user isinya apa ?? id user ?

jadi kan kodenya di rubah ke $user = users::where('id', $user)->first(); tapinya error

Login untuk ikut Jawaban