I am setting up user profile page, but I cannot insert data into mysql server.
I cannot figure it out and solve this issue.
I have index.blade.php in my profile folder, and from index page, going to create.blade.php .
When I enter the submit button, my page redirects to index.blade.php, but in mysql server, nothing is recorded.
web.php
Route::prefix('user')->group(function(){
Route::resource('profile', 'UserController');
});
create.blade.php
<form action="" method="POST">@csrf
<ul class="information">
<li>Name :<br>
<input type="text" class="name" name="name">
</li><br>
<li>Gender :<br>
<div class="gender">
<select name="gender" id="" name="gender">
<option class="option" value="" selected="selected">Select Gender</option>
<option value="male" >Male</option>
<option value="female" class="selected">Female</option>
<option value="any">Any</option>
</select>
</div>
</li>
<li>Country :<br>
<div class="country">
<select name="country" id="" name="country">
<option value="" selected="selected">Select Country</option>
<option value="United States" class="selected">United States</option>
<option value="United Kingdom">United Kingdom</option>
</select>
</div>
</li><br>
<li>Birthday :<br>
<input type="text" class="birthday" id="bod" name="bod">
</li><br>
<li>User Description :<br>
<textarea name="description" id="" cols="60" rows="10"></textarea></li>
</ul>
<button type="submit" class="saveBtn">Save</button>
</div>
</form>
</div>
UserController.php
public function index()
{
return view('profile.index');
}
public function create()
{
return view('profile.create');
}
public function store(Request $request) {
$user_id = auth()->user()->id;
Profile::where('user_id',$user_id)->update([
'name'=>request('name'),
'gender'=>request('gender'),
'country'=>request('country'),
'bod'=>request('bod'),
'description'=>request('description')
]);
return redirect()->route('profile.index');
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire