I am currently running into an issue with my update function in my UserController. The only field that will update correctly is the eid field, all other fields just cause the page to refresh.
I have looked at several other update function examples and I can't determine what
public function update(Request $request, $id)
{
$this->validate($request,[
'name' => 'required|max:255',
'eid' => 'required|max:255|unique:users',
'email' => 'required|email|unique:users,email,'.$id,
]);
$user = User::findOrFail($id);
$user->name = $request->name;
$user->eid = $request->eid;
$user->email = $request->email;
if (!empty($request->password)) {
$user->password = Hash::make($request->password);
}
$user->save();
return redirect()->route('users.show', $id);
edit.blade.php
<form action="{{route('users.update', $user->id)}}" method="POST">
{{csrf_field()}}
{{method_field('PATCH')}}
<div class="field">
<label for="name" class="label">Name</label>
<p class="control">
<input type="text" class="input" name="name" id="name" value="{{$user->name}}">
</p>
</div>
<div class="field">
<label for="eid" class="label">EID</label>
<p class="control">
<input type="text" class="input" name="eid" id="eid" value="{{$user->eid}}">
</p>
</div>
<div class="field">
<label for="email" class="label">Email</label>
<p class="control">
<input type="text" class="input" name="email" id="email" value="{{$user->email}}">
</p>
</div>
<div class="field">
<label for="password" class="label">Password</label>
<p class="control m-t-10">
<input type="text" class="input" name="password" id="password" placeholder="Enter your password">
</p>
</div>
<button class="button is-success is-pulled-right" type="submit">Update User</button>
</form>
Migration File
Schema::create('users', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('eid');
$table->string('email')->unique();
$table->string('password');
$table->rememberToken();
$table->timestamps();
});
dd results
array:5 [▼
"_token" => "uG3qvyPAa2OBGFUZ7PNwNRKhupNyQLeptxHsSi8a"
"_method" => "PATCH"
"name" => "Agent11"
"eid" => "RQrOwau11"
"email" => "agent12@app.com"
]
dd after validation
User {#271 ▼
#fillable: array:4 [▼
0 => "name"
1 => "eid"
2 => "email"
3 => "password"
]
#hidden: array:2 [▶]
#connection: "mysql"
#table: null
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:8 [▼
"id" => 6
"name" => "Agent11"
"eid" => "RQrOwau"
"email" => "agent@app.com"
"password" => "$2y$10$KC3UVyoLPhtb/omRT8gxjuHe/QB8t5Lj/JYLugbHMfQ9O4NyduV5a"
"remember_token" => null
"created_at" => "2017-12-19 15:21:23"
"updated_at" => "2017-12-21 10:33:40"
]
#original: array:8 [▼
"id" => 6
"name" => "Agent11"
"eid" => "RQrOwau"
"email" => "agent@app.com"
"password" => "$2y$10$KC3UVyoLPhtb/omRT8gxjuHe/QB8t5Lj/JYLugbHMfQ9O4NyduV5a"
"remember_token" => null
"created_at" => "2017-12-19 15:21:23"
"updated_at" => "2017-12-21 10:33:40"
]
#changes: []
#casts: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#visible: []
#guarded: array:1 [▶]
#rememberTokenName: "remember_token"
dd after save
User {#271 ▼
#fillable: array:4 [▼
0 => "name"
1 => "eid"
2 => "email"
3 => "password"
]
#hidden: array:2 [▼
0 => "password"
1 => "remember_token"
]
#connection: "mysql"
#table: null
#primaryKey: "id"
#keyType: "int"
+incrementing: true
#with: []
#withCount: []
#perPage: 15
+exists: true
+wasRecentlyCreated: false
#attributes: array:8 [▼
"id" => 6
"name" => "Agent11"
"eid" => "RQrOwau"
"email" => "agent@app.com"
"password" => "$2y$10$KC3UVyoLPhtb/omRT8gxjuHe/QB8t5Lj/JYLugbHMfQ9O4NyduV5a"
"remember_token" => null
"created_at" => "2017-12-19 15:21:23"
"updated_at" => "2017-12-21 10:50:46"
]
#original: array:8 [▼
"id" => 6
"name" => "Agent11"
"eid" => "RQrOwau"
"email" => "agent@app.com"
"password" => "$2y$10$KC3UVyoLPhtb/omRT8gxjuHe/QB8t5Lj/JYLugbHMfQ9O4NyduV5a"
"remember_token" => null
"created_at" => "2017-12-19 15:21:23"
"updated_at" => "2017-12-21 10:50:46"
]
#changes: []
#casts: []
#dates: []
#dateFormat: null
#appends: []
#dispatchesEvents: []
#observables: []
#relations: []
#touches: []
+timestamps: true
#visible: []
#guarded: array:1 [▶]
#rememberTokenName: "remember_token"
}