Registration Form is not submitting data into Database Laravel 5.2 - php

I have installed laravel authentication(Scaffolding) to my Point of Sale application , registration form was working fine BUT I created an Admin middle ware and I restricted the /register to admin only , I can get the view from my admin panel when admin is logged in but when I submit data it sends nothing to database.
PS: If any thing else is need just mention in comments.
Registration View:
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Register</div>
<div class="panel-body">
<form class="form-horizontal" role="form" method="POST" action="{{ url('/register') }}">
{!! csrf_field() !!}
<div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
<label class="col-md-4 control-label">Name</label>
<div class="col-md-6">
<input type="text" class="form-control" name="name" value="{{ old('name') }}">
#if ($errors->has('name'))
<span class="help-block">
<strong>{{ $errors->first('name') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6">
<input type="email" class="form-control" name="email" value="{{ old('email') }}">
#if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label class="col-md-4 control-label">Password</label>
<div class="col-md-6">
<input type="password" class="form-control" name="password">
#if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group{{ $errors->has('password_confirmation') ? ' has-error' : '' }}">
<label class="col-md-4 control-label">Confirm Password</label>
<div class="col-md-6">
<input type="password" class="form-control" name="password_confirmation">
#if ($errors->has('password_confirmation'))
<span class="help-block">
<strong>{{ $errors->first('password_confirmation') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
<i class="fa fa-btn fa-user"></i>Register
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
Routes:
Route::group(['middleware' => 'web'], function () {
Route::get('/', function () {
return view('welcome');
});
Route::auth();
Route::get('/home', 'HomeController#index');
Route::get('/register', function(){
return view('auth.register');
})->middleware('isAdmin');
});
HomeController:
<?php
namespace App\Http\Controllers;
use App\Http\Requests;
use Illuminate\Http\Request;
class HomeController extends Controller
{
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('auth');
}
/**
* Show the application dashboard.
*
* #return \Illuminate\Http\Response
*/
public function index()
{
return view('home');
}
}

Try using fillable in User.php
For Example:
If you want to store name, email and password, make sure you have
protected $fillable = ['name', 'email', 'password'];
in your User.php

Related

Too few arguments to function App\Http\Controllers\Auth\RegisterController::createuser(), 0 passed and exactly 1 expected

I used hyn/tenancy https://tenancy.dev/docs/hyn/5.4 and created an application like this: https://www.seismicpixels.com/creating-a-laravel-saas-framework-part-6/
At the moment I'm having the problem that I'm trying to setup a registration controller for users within the tenant. I tried doing this with a second public function in the registration controller
protected function createuser(array $data)
{
print_r($data);
die();
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => Hash::make($data['password']),
]);
}
The showRegistrationForm() function is:
/**
* Show the application registration form.
*
* #return \Illuminate\Http\Response
*/
public function showRegistrationForm()
{
return view('auth.registeruser');
}
The error I'm facing is (as far as i do understand), says that there's no array, which could be selected as $data . I tried using the die() like above but array $data isn't going through.
I also tried using the standard registration page which is
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Register</div>
<div class="panel-body">
<form class="form-horizontal" role="form" method="POST" action="{{ route('register.users') }}">
{{ csrf_field() }}
<div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
<label for="name" class="col-md-4 control-label">Name</label>
<div class="col-md-6">
<input id="name" type="text" class="form-control" name="name" value="{{ old('name') }}" required autofocus>
#if ($errors->has('name'))
<span class="help-block">
<strong>{{ $errors->first('name') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" required>
#if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label for="password" class="col-md-4 control-label">Password</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="password" required>
#if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group">
<label for="password-confirm" class="col-md-4 control-label">Confirm Password</label>
<div class="col-md-6">
<input id="password-confirm" type="password" class="form-control" name="password_confirmation" required>
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Register
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
and here's my web.php where the registration routes are shown, but I don't think the problem is within here because i'm getting an error out of the function, so the routing works?
// Register Routes
Route::get('register', 'Auth\RegisterUserController#showRegistrationForm')->name('register.user');
Route::post('registeruser', 'Auth\RegisterController#createuser')->name('register.users');
I hope somebody can help me with this error (probably on my side 🙈)
Thanks in advance!
Try This:
protected function createuser(Request $request)
{
print_r($request->name);
die();
return User::create([
'name' => $request->name,
'email' => $request->email,
'password' => Hash::make($request->password),
]);
}
You are passing the $data as parameter but not definig it in you route:
try this hope it will help you!
Your registers.users should use Auth\RegisterController#register method. createuser is called inline and receives $request->all()
Btw, default name for the function is create(), no createuser (if you don't want to modify register method)

Display issue in Laravel 5.5 registration form's errors

I created a registration form using make:auth command in Laravel 5.5. Its working alright but not showing errors when validation fails. I've checked many times that code to display errors exists in template but still getting this error.
Template Location:
resources/views/mybladetemplate
Method in Controller:
protected function validator(array $data)
{
return Validator::make($data, [
'field1' => 'required|string|max:255',
'emailField' => 'required|string|email|max:255|unique:users',
'fieldPwd' => 'required|string|min:6|confirmed',
'anotherfield' => 'string'
]);
}
RegistersUsers Trait:
public function register(Request $request)
{
$this->validator($request->all())->validate();
event(new Registered($user = $this->create($request->all())));
$this->guard()->login($user);
return $this->registered($request, $user)
?: redirect($this->redirectPath());
}
Registeration Form:
<form class="form-horizontal" method="POST" action="{{ route('register') }}">
{{ csrf_field() }}
<div class="form-group{{ $errors->has('field1') ? ' has-error' : '' }}">
<label for="name" class="col-md-4 control-label">Field Name</label>
<div class="col-md-6">
<input id="field1" type="text" class="form-control" name="field" value="{{ old('field1') }}" required autofocus>
#if ($errors->has('field1'))
<span class="help-block">
<strong>{{ $errors->first('field1') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group{{ $errors->has('emailField') ? ' has-error' : '' }}">
<label for="email" class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6">
<input id="emailField" type="email" class="form-control" name="emailField" value="{{ old('emailField') }}" required>
#if ($errors->has('emailField'))
<span class="help-block">
<strong>{{ $errors->first('emailField') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group">
<label for="anotherfield" class="col-md-4 control-label">Another Field</label>
<div class="col-md-6">
<input id="anotherfield" type="text" class="form-control" name="anotherfield" value="{{ old('anotherfield') }}" />
</div>
</div>
<div class="form-group{{ $errors->has('fieldPwd') ? ' has-error' : '' }}">
<label for="fieldPwd" class="col-md-4 control-label">Password</label>
<div class="col-md-6">
<input id="fieldPwd" type="password" class="form-control" name="fieldPwd" required>
#if ($errors->has('fieldPwd'))
<span class="help-block">
<strong>{{ $errors->first('fieldPwd') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group">
<label for="password-confirm" class="col-md-4 control-label">Confirm Password</label>
<div class="col-md-6">
<input id="password-confirm" type="password" class="form-control" name="password_confirmation" required>
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Register
</button>
</div>
</div>
</form>
Use this simple code in your blade to show all of the errors in a ul li structure :
#if($errors->any())
#foreach ($errors->all() as $error)
<div class="alert alert-warning" dir="rtl">
<ul>
<li>{!! $error !!}</li>
</ul>
</div>
#endforeach
#endif

make:auth() Login/Register not working

I am working with Laravel 5.5. I created login/register page with make:auth about 1 month ago and didn't change anything inside Laravel auth core files.
I just register and, after that I want to login. Login page reloaded when I hit login button and don't give any error messages. I don't know what's wrong. This code worked during 1 month and from yesterday it doesn't work right.
I just attached my login/register files here.
Auth Register Controller
<?php
namespace App\Http\Controllers\Auth;
use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
class RegisterController extends Controller {
use RegistersUsers;
protected $redirectTo = '/home';
public function __construct()
{
$this->middleware('guest');
}
protected function validator(array $data)
{
return Validator::make($data, [
'member_id' => 'required|string|integer|min:000000|max:999999',
'password' => 'required|string|min:6|confirmed',
]);
}
protected function create(array $data)
{
return User::create([
'member_id' => $data['member_id'],
'password' => bcrypt($data['password']),
]);
}
This is my register.blade.php
<form class="form-horizontal" method="POST" action="{{ route('register') }}">
{{ csrf_field() }}
<div class="form-group{{ $errors->has('member_id') ? ' has-error' : '' }}">
<label for="member_id" class="col-md-4 control-label">
{{ Lang::get('all.info.member_id') }}
</label>
<div class="col-md-6">
<input id="member_id" type="number" onkeypress='return event.charCode >= 48 && event.charCode <= 57' class="form-control" name="member_id" value="{{ old('member_id') }}" required>
#if ($errors->has('member_id'))
<span class="help-block">
<strong>{{ $errors->first('member_id') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label for="password" class="col-md-4 control-label">
{{ Lang::get('all.info.password') }}
</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="password" required>
#if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group">
<label for="password-confirm" class="col-md-4 control-label">
{{ Lang::get('all.info.confirm_password') }}
</label>
<div class="col-md-6">
<input id="password-confirm" type="password" class="form-control" name="password_confirmation" required>
</div>
</div>
</form>
This is my login.blade.php
<form class="form-horizontal" method="POST" action="{{ route('login') }}">
{{ csrf_field() }}
<div class="form-group{{ $errors->has('scout_id') ? ' has-error' : '' }}">
<label for="scout_id" class="col-md-4 control-label">
{{ Lang::get('all.login_p.scout_id') }}
</label>
<div class="col-md-6">
<input id="member_id" type="number" onkeypress='return event.charCode >= 48 && event.charCode <= 57' class="form-control" name="member_id" value="{{ old('member_id') }}" required autofocus>
#if ($errors->has('member_id'))
<span class="help-block">
<strong>{{ $errors->first('member_id') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label for="password" class="col-md-4 control-label">
{{ Lang::get('all.login_p.password') }}
</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="password" required>
#if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group">
<div class="col-md-8 col-md-offset-4">
<button type="submit" class="btn btn-primary">
{{ Lang::get('all.login') }}
</button>
</div>
</div>
</form>
did you use Auth::attempt(); ?
Auth::attempt(['member_id' => $request->member_id, 'password' => $request->password]);
You are not telling the LoginController that your 'email'/'username' field is not email. You have to tell it you want to use a different field.
Username Customization
"By default, Laravel uses the email field for authentication. If you would like to customize this, you may define a username method on your LoginController:"
public function username()
{
return 'member_id';
}
Laravel 5.5 Docs - Authentication - Authentication Quickstart - Authenticating

Laravel Second registration form

I'm working on laravel 5.4 i have 3 type of users and all of them working perfectly, 1 of them of course is admin and the 2 other is users and companies, users are using auth default login nd register form and there is no issue on that, what my issue is for companies to register i need a new form I made a blade for companies registration form and register controller for them in app/http/auth folder now form will loading and when I try to save the form it returns me this error:
FatalThrowableError in CompanyRegisterController.php line 54: Type error: Too few arguments to function App\Http\Controllers\Auth\CompanyRegisterController::create(), 0 passed and exactly 1 expected
My line 54 is:
protected function create(array $data)
this is my complete companyregistercontroller:
<?php
namespace App\Http\Controllers\Auth;
use Illuminate\Http\Request;
use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;
class CompanyRegisterController extends Controller
{
/**
* Where to redirect users after registration.
*
* #var string
*/
protected $redirectTo = 'companies';
public function __construct() {
$this->middleware('guest:company');
}
protected function index()
{
return view('auth.company-register');
}
/**
* Get a validator for an incoming registration request.
*
* #param array $data
* #return \Illuminate\Contracts\Validation\Validator
*/
protected function validator(array $data)
{
return Validator::make($data, [
'company_name' => 'required|string|max:255',
'manager_name' => 'required|string|max:255',
'address' => 'required|string|max:255',
'username' => 'required',
'email' => 'required|string|email|max:255|unique:users',
'about' => 'sometimes|min:10|max:2000',
'password' => 'required|string|min:6|confirmed',
]);
}
/**
* Create a new user instance after a valid registration.
*
* #param array $data
* #return User
*/
protected function create(array $data)
{
return Company::create([
'company_name' => $data['company_name'],
'manager_name' => $data['manager_name'],
'address' => $data['address'],
'username' => $data['username'],
'about' => $data['about'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
}
UPDATE
My view codes
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Companies Register form <span style="float:right;" data-toggle="tooltip" data-placement="top" title="If you need to hire people click here."><i class="fa fa-building"></i> Company register</span></div>
<div class="panel-body">
<p>
<img src="{{ asset('images/signup-icon.png') }}" class="img-responsive img-circle regimg" alt="Register" >
</p>
<form class="form-horizontal" role="form" method="POST" action="{{ route('company.register.submit') }}">
{{ csrf_field() }}
<div class="row">
<div class="col-md-6">
<div class="form-group{{ $errors->has('company_name') ? ' has-error' : '' }}">
<label for="company_name" class="col-md-4 control-label"><i class="fa fa-user-circle"></i> Company Name</label>
<div class="col-md-8">
<input id="company_name" type="text" class="form-control" name="company_name" value="{{ old('company_name') }}" required autofocus>
#if ($errors->has('company_name'))
<span class="help-block">
<strong>{{ $errors->first('company_name') }}</strong>
</span>
#endif
</div>
</div>
</div><!-- end col-md-6 -->
<div class="col-md-6">
<div class="form-group{{ $errors->has('manager_name') ? ' has-error' : '' }}">
<label for="manager_name" class="col-md-4 control-label"><i class="fa fa-user-circle-o"></i> Manager Name</label>
<div class="col-md-8">
<input id="manager_name" type="text" class="form-control" name="manager_name" value="{{ old('manager_name') }}" required autofocus>
#if ($errors->has('manager_name'))
<span class="help-block">
<strong>{{ $errors->first('manager_name') }}</strong>
</span>
#endif
</div>
</div>
</div><!-- end col-md-6 -->
</div>
<div class="row">
<div class="col-md-6">
<div class="form-group{{ $errors->has('address') ? ' has-error' : '' }}">
<label for="address" class="col-md-4 control-label"><i class="fa fa-address-book"></i> Address</label>
<div class="col-md-8">
<input id="address" type="text" class="form-control" name="address" value="{{ old('address') }}" required autofocus>
#if ($errors->has('address'))
<span class="help-block">
<strong>{{ $errors->first('address') }}</strong>
</span>
#endif
</div>
</div>
</div><!-- end col-md-6 -->
<div class="col-md-6">
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="col-md-4 control-label"><i class="fa fa-envelope"></i> E-Mail Address</label>
<div class="col-md-8">
<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}" required>
#if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
#endif
</div>
</div>
</div><!-- end col-md-6 -->
</div>
<div class="form-group{{ $errors->has('username') ? ' has-error' : '' }}">
<label for="username" class="col-md-4 control-label"><i class="fa fa-birthday-cake"></i> username</label>
<div class="col-md-6">
<input id="username" type="text" class="form-control" name="username" value="{{ old('username') }}" autofocus>
#if ($errors->has('username'))
<span class="help-block">
<strong>{{ $errors->first('username') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group{{ $errors->has('about') ? ' has-error' : '' }}">
<label for="about" class="col-md-4 control-label"><i class="fa fa-birthday-cake"></i> about</label>
<div class="col-md-6">
<input id="about" type="textarea" class="form-control" name="about" value="{{ old('about') }}" autofocus>
#if ($errors->has('about'))
<span class="help-block">
<strong>{{ $errors->first('about') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label for="password" class="col-md-4 control-label"><i class="fa fa-key"></i> Password</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="password" required>
#if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group">
<label for="password-confirm" class="col-md-4 control-label"><i class="fa fa-unlock-alt"></i> Confirm Password</label>
<div class="col-md-6">
<input id="password-confirm" type="password" class="form-control" name="password_confirmation" required>
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-success btn-bg btn-block">
<i class="fa fa-registered"></i> Register
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
Any idea why this doesn't work?

Laravel 5.3 Session store not set on request

I have a Laravel project and I'm getting the following error and tried other questions asked before but i can't understand the problem. plz anybody guide me.
RuntimeException in C:\xampp\htdocs\project\vendor\laravel\framework\src\Illuminate\Http\Request.php line 905:
My routes.php file is here:
Route::group(['middleware' => ['web']], function () {
// default public route
Route::get('/', 'DashboardController#index');
// Rediret for Login Page
Route::get('/loginmsg', 'LoginMessageController#index');
// dashboard route
Route::get('dashboard/index', 'DashboardController#index');
});
//Route::get('/service/get/login','App\Http\Controllers\Auth\LoginMessageController#index')->name('xyz');
Route::group(['middleware' => 'web'], function () {
Route::auth();
Route::get('register', 'DashboardController#index');
});
Here's my register.blade.php
#extends('layouts.app')
#section('content')
<div class="container">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<div class="panel panel-default">
<div class="panel-heading">Register</div>
<div class="panel-body">
<form class="form-horizontal" role="form" method="POST" action="{{ url('/register') }}">
{{ csrf_field() }}
<div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}">
<label for="name" class="col-md-4 control-label">Name</label>
<div class="col-md-6">
<input id="name" type="text" class="form-control" name="name" value="{{ old('name') }}">
#if ($errors->has('name'))
<span class="help-block">
<strong>{{ $errors->first('name') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="col-md-4 control-label">E-Mail Address</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control" name="email" value="{{ old('email') }}">
#if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label for="password" class="col-md-4 control-label">Password</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control" name="password">
#if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group{{ $errors->has('password_confirmation') ? ' has-error' : '' }}">
<label for="password-confirm" class="col-md-4 control-label">Confirm Password</label>
<div class="col-md-6">
<input id="password-confirm" type="password" class="form-control" name="password_confirmation">
#if ($errors->has('password_confirmation'))
<span class="help-block">
<strong>{{ $errors->first('password_confirmation') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">
<i class="fa fa-btn fa-user"></i> Register
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection

Categories