mardi 29 novembre 2016

why do not update values in Laravel

I am going to insert and update values using My addpermission function in My Controller

public function addPermission(Request $request, $id, $permission = null) 
{
  $this->validate($request, [
    'status'   => 'required'
  ]);

  if(is_null($permission)) {
    $permission = new Permission;
    $msg = 'Permission has been added to your Collaborator successfully';
  } else {
    $permission = Permission::findOrFail($permission,['id'])->id;
    $msg = 'Permission updated successfully';
  }

  $permission->status = $request->input('status');
  $permission->project_id       = $id;
  $permission->collaborator_id =  $request->input('cid');
  $permission->save();
  return redirect()->back()->with('info', $msg);
}

My routes

Route::post('projects/{project_id}/permission', [
    'uses' => 'ProjectCollaboratorsController@addPermission',
    'as'   => 'projects.collaborators.permission',
  //  'middleware' => ['auth']
]);

data insert go successfully. but update not success when I click button to update it is insert as new record to DB.

My table name is permission and have these columns

id (autoincrement) status project_id collaborator_id

how can fix this?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire