dimanche 10 juillet 2016

How to update table from form laravel 5.1

Hey Guys im trying to have this form update my users table but im not sure how to do it in laravel. Here is my form

<form method="POST" action="/profile/update">
    <div class="form-group hidden">
        <input type="hidden" name="_token" value="">
        <input type="hidden" name="id" value="<?php echo $user->id;?>">
        <input type="hidden" name="_method" value="PATCH">
    </div>
    <div class="form-group">
        <label for="email"><b>Name:</b></label>
        <input type="text" name="name" placeholder="Please enter your email here" class="form-control" value="<?php echo $user->name;?>"/>
    </div>
    <div class="form-group">
        <label for="email"><b>Email:</b></label>
        <input type="text" name="email" placeholder="Please enter your email here" class="form-control" value="<?php echo $user->email;?>"/>
    </div>
    <div class="form-group">
        <button type="submit" class="btn btn-default"> Submit </button>
    </div>
</form>

Here is my controller

<?php

namespace App\Http\Controllers;

use Auth;
use App\User;
use Illuminate\Http\Request;

use App\Http\Controllers\Controller;

class ProfileController extends Controller
{
    /**
     * Update user profile & make backend push to DB
    **/

    public function index() {

        // connecting to the DB and accessing
        $user = Auth::user();
        //var_dump($user);
        return view('profile', compact('user'));

    }

    public function update(Request $request) {

        $request->only('name','email');
        return back();
    }
}

my update method will handle the input but im not sure what to do from here.

Thanks for all the help



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire