mardi 6 mars 2018

Update one field in Laravel 5.5 from show view

I am trying to update only one field in table from show view. Here is my update function

public function update(Request $request, $id)
{
    $topic = Topic::find($id);
    $this->validate(request(), [
      'name' => 'required',
      'category_id' => 'required',
      'description' => 'required'
    ]);
    $topic->name = $request->get('name');
    $topic->category_id = $request->get('category_id');
    $topic->description = $request->get('description');
    $topic->assignedTo = $request->get('assignedTo');
    $topic->save();
    return redirect('manage/topics')->with('success','Topic has been updated');
}

And here's form in blade

<div>
  <label for="name" class="label">Student Name</label>
    <ul class="list-group">
      @foreach($applicants as $ap)
        <li class="list-group-item d-flex justify-content-between align-
        items-center">
        
   <form action="" 
   method="post">
 
 <input name="_method" type="hidden" value="PATCH">
 <button class="badge badge-pill badge-warning" type="submit" value="" name="assignedTo">
  Assign To
  </button>
  </form>
  </li>
  @endforeach
  </ul>
  </div>

So I'm trying to update column 'assignedTo' in topics table with user id. In the topic show function i get all users who applied for that topic. And I have a button next to names, to update "assignedTo" in Topics table with user_id. When i click on apply it redirects to show function.

any help would be appreciated

Here is view



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2G0AmGa
via IFTTT

Aucun commentaire:

Enregistrer un commentaire