vendredi 17 avril 2020

how to make form submit data to database? creating a new user

I am trying to submit a form in order to create a new user, when i click submit a new user is not created. can someone please help me as i am not sure where i am going wrong. thank you.

this is the sign up page

@extends('layouts.master')
@section('content')
<div class="row">
<div class="col-md-4 col-md-offset-4">
<h1>Sign Up</h1>
@if(count($errors) > 0)
<div class="alert alert-danger">
@foreach($errors->all() as $error)
<p></p>
@endforeach
</div>
@endif
<form action="" method="post">
<div class="form-group">
<label for="email">E-Mail</label>
 <input type="text" id="email" name="email" class="form-control">
</div>
<div class="form-group">
<label for="password">Password</label>
 <input type="password" id="password" name="password" class="form-control">
</div>
<button type="submit" class="btn btn-primary">Sign Up</button>

</form>
</div>
</div>
 @endsection

this is my controller

<?php

namespace App\Http\Controllers;

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

use App\Http\Requests;

class UserController extends Controller
{
     public function getSignup()
    {
        return view('user.signup');
    }

    public function postSignup(Request $request){
        $this->validate($request, [
        'email' => 'email|required|unique:users',
        'password' => 'required|min:4'
        ]);

        $user = new User([
        'email' => $request->input('email'),
         'password' => bcrypt($request->input('password'))
    ]);
    $user->save();

    return redirect()->route('product.index');
   }
   }

im using it here like this:

          <li><a href="">Signup</a></li>

these are the two routes i have set up

Route::get('/signup', 'UserController@getSignup')->name('user.signup');


Route::post('/signup', 'UserController@postSignup')->name('user.signup');


via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire