mardi 15 mai 2018

How to update the users table in laravel?

I want to update the value of one column of the 'users' table. This is the code of the controller:

<?php


  class RankController extends Controller
{
public function index()
{
    //
}

/**
 * Show the form for creating a new resource.
 *
 * @return \Illuminate\Http\Response
 */
public function create()
{   
    // Create an array of all  users
    $users = User::all();
    // Return the view of change rank with users
    return view('rank.edit')->with('users', $users);
}


public function store(Request $request)
{
   $this->validate($request, [
        'rank' => 'required',
        'user_name' => 'required',
 ]);
 $id = $request->input('user_name');
 // Create reply
 $user = User::find($id);
 $user->rank = $request->input('rank');
 $user->save();


 return redirect('../public/home')->with('succes', 'The rank id is'.$id.'         '.$user.'<br>'.'<br>'.$user->rank);

  }

public function show($id)
{
    //
}


public function edit($id)
{

}


public function update(Request $request, id)
{
    //
}


public function destroy($id)
{
    //
}


}

After checking the variables I find the problem: 'save()' method doesn't work, and I cant't figure out why it doesn't work. Any ideas why doesn't work? Thanks in advance!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire