Nishanth  Nishanth -3 years ago 124
PHP Question

update values using user id in laravel

How can i update the values by using the user id.The controller,layout and route are at the below cases as follows:


public function profileedit() {

$id = \Auth::user()->id;
$user_id = \Auth::user()->user_id;

$teacheredit = DB::table('teachers')
//->join('campaign_type', 'campaign.campaign_id', '=', '')
//->select('campaign.*', 'campaign_type.*',' as campaignid','campaign.status as campaign_status')
->select('teachers.*', ' as teacher_id')
->where('', '=', $user_id)

return view('layouts.teacher.profile', array('teacheredit' => $teacheredit));

public function profileupdate($ids, Request $request) {
$profile = Teachers::find($ids);
$id = \Auth::user()->id;
$user_id = \Auth::user()->user_id;

$subscriber_id = \Auth::user()->subscriber_id;
$inputteacher = $request->all();

$profileeditdata = array(
'teacherFirstName' => $inputteacher['teacher_firstname'],
'teacherLastName' => $inputteacher['teacher_lastname'],

// \Session::flash('success', 'Data Insert Successfully!');
return Redirect('/teacher/profile');

In this case edit is working but updation is not working please provide me a help.


<div id="createStudent" type="view" class="demo-section k-header">
{!! Form::open(array('url' => 'profileupdate/'.$teacheredit[0]->teacher_id,'class'=>'horizontal-form'))!!}

<form id="createTeacherForm" method="post" action="../teacherregistration" >

<ul id="fieldlist" >
<label style="color:Green;font-size:15px">Profile</label>
<table id="lessonPlanTable">
<td><label> UserType </label> </td>
<td><label> <?= $teacheredit[0]->teacher_firstname ?> </label></td>
<td><label> First Name </label> </td>
<td><input type="text" id="teacher_firstname" name="teacher_firstname" value="<?php echo $teacheredit[0]->teacher_firstname ?>" class="k-textbox"/></td>
<td><label> Last Name </label> </td>
<td><input type="text" id="teacher_lastname" name="teacher_lastname" value="<?php echo $teacheredit[0]->teacher_lastname ?>" class="k-textbox"/></td>

<td><label> Email </label> </td>
<td><input type="email" id="teacherEmail" name="teacherEmail" value="<?php echo $teacheredit[0]->teacher_email ?>" class="k-textbox"/ readonly></td>
<button id="updateTeacherProfile" class="k-button k-primary" type="submit">Update</button>&nbsp;&nbsp;
<button id="resetTeacherPassword" class="k-button k-primary" type="button" style="width:20%">Reset Password</button>




Route::get('/teacher/profile', 'Teacher\TeacherController@profileedit');
Route::post('profileupdate/{id}', 'Teacher\TeacherController@profileUpdate');

edit is perfectly working without any errors but in updation i make to check the answer using dd() it return the correct answer but after hiding dd() the result will not be updated..

Answer Source

Try to update record with below code:

$profile = Teachers::find($ids);
$profile->teacherFirstName = $inputteacher['teacher_firstname'];
$profile->teacherLastName = $inputteacher['teacher_lastname'];

Note: Removed the fill() because your next method profileedit() already having select for the same records.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download