Please help me to add upload profile picture on laravel 5.2 registration form.
I use Auth for my registration and login, but made some modification there.
this is my register.blade.php 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-primary">
<div class="panel-heading">Pendaftaran Akun Baru</div>
<div class="panel-body">
<form class="form-horizontal" role="form" method="POST" action="{{ url('/register') }}">
{!! csrf_field() !!}
<!-- start of nip -->
<div class="form-group{{ $errors->has('nip') ? ' has-error' : '' }}">
<label class="col-md-4 control-label">Nomor Induk Pegawai</label>
<div class="col-md-6">
<input type="text" class="form-control" name="nip" value="{{ old('nip') }}">
#if ($errors->has('nip'))
<span class="help-block">
<strong>{{ $errors->first('nip') }}</strong>
</span>
#endif
</div>
</div>
<!-- end of nip -->
<!-- start of nama -->
<div class="form-group{{ $errors->has('nama') ? ' has-error' : '' }}">
<label class="col-md-4 control-label">Nama</label>
<div class="col-md-6">
<input type="text" class="form-control" name="nama" value="{{ old('nama') }}">
#if ($errors->has('nama'))
<span class="help-block">
<strong>{{ $errors->first('nama') }}</strong>
</span>
#endif
</div>
</div>
<!-- end of nama -->
<!-- start of email -->
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label class="col-md-4 control-label">Alamat E-mail</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>
<!-- end of email -->
<!-- start of password -->
<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>
<!-- end of password -->
<!-- start of konfirmasi -->
<div class="form-group{{ $errors->has('password_confirmation') ? ' has-error' : '' }}">
<label class="col-md-4 control-label">Konfirmasi 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>
<!-- end of konfirmasi -->
<!-- start of foto -->
<div class="form-group{{ $errors->has('avatar') ? ' has-error' : '' }}">
<label class="col-md-4 control-label">F o t o</label>
<div class="col-md-6">
<div id="kv-avatar-errors" class="center-block" style="width:800px;display:none">
</div>
<div class="kv-avatar" style="width:200px">
<input id="avatar" name="avatar" type="file" class="file-loading">
</div>
</div>
</div>
<!-- end of foto -->
<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>Daftar
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
this is my eloquent app\Daftarpegawai.php
<?php
namespace App;
use Illuminate\Foundation\Auth\User as Authenticatable;
class Daftarpegawai extends Authenticatable {
protected $fillable = [
'nip', 'nama', 'email', 'password', 'foto',
];
protected $hidden = [
'password', 'status', 'remember_token',
];
}
and this is my AuthController.php
<?php
namespace App\Http\Controllers\Auth;
use App\Daftarpegawai;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
class AuthController extends Controller
{
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
protected $redirectTo = '/';
public function __construct()
{
$this->middleware($this->guestMiddleware(), ['except' => 'logout']);
}
protected function validator(array $data)
{
return Validator::make($data, [
'nip' => 'required|max:20',
'nama' => 'required|max:255',
'avatar' => 'mimes:jpg',
'email' => 'required|email|max:255|unique:daftarpegawais',
'password' => 'required|confirmed|min:6',
]);
}
protected function create(array $data)
{
return Daftarpegawai::create([
'nip' => $data['nip'],
'nama' => $data['nama'],
'foto' => $data['avatar'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
}
I am new in learning laravel
i've tried some methods that i found here with the same problem, but nothing works for me
if($data->hasFile('avatar'))
{
$destinationPath = 'path/to/upload/the/file'
$imgName = 'yourimagename.jpg'
$data->avatar->move($destinationPath, $imgName)
$path = $destinationPath . '/' . $imgName
}
DaftarPegawai::create([
'foto' => $path
])
You can use the below code as your POST request code for uploading avatar to user profile
public function update_avatar(Request $request){
$request->validate([
'avatar' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);
$user = Auth::user();
$avatarName = $user->id.'_avatar'.time().'.'.request()->avatar-
>getClientOriginalExtension();
$request->avatar->storeAs('avatars',$avatarName);
$user->avatar = $avatarName;
$user->save();
return back()
->with('success','You have successfully upload image.');
}
Source : Detailed tutorial https://www.5balloons.info/upload-profile-picture-avatar-laravel-5-authentication/
If someone is still facing problem, try using the following codes! Hope it will work...
$avatar = $data['avatar'];
$extension = $avatar->getClientOriginalExtension();
$avatar_name = time() . '.' . $extension;
$avatar->move(base_path('public/images/avatars/'), $avatar_name);
return User::create([
'avatar' => $avatar_name,
]);
Related
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)
In my laravel project am using js validator, but during form updation , Validation is not working. My form is not submitting, if I did not made any changes. Sometimes it shows error to the email field.
Following is my validation code,
protected $edituserValidationRules = [
'user_name' => 'required',
'email' => 'required|email|max:255|unique:users',
];
Following is the code to pass validation and other things to view
public function viewUsers($id)
{
$users = User::find($id);
$validator = JsValidator::make($this->edituserValidationRules,[],[],'#useredit');
return view('user.update')->with(['validator' => $validator,'users'=> $users]);
}
Following is the code to update that particular user
public function updateUsers(Request $request , $id)
{
$this->validate($request, [
'email' => 'required|email|max:255|unique:users' . $request->id
]);
$postdata = $request->all();
$user = new User;
$user = User::find($id);
$hashedRandomPassword = Hash::make($postdata['password'], [
'rounds' => 12
]);
$api_key = Str::random(16);
$checkApiKey = User::where('api_key', $api_key)->first();
if(!empty($checkApiKey)) {
$api_key = Str::random(16);
}
$user = new User;
$user->name=$postdata['user_name'];
$user->email=$postdata['email'];
$user->password= $hashedRandomPassword;
$user->ip_address=$request->ip();
$user->api_key=$api_key;
if($user->save()){
Session::flash('message', 'User Updated Sucessfully');
Session::flash('msgclass', 'alert-success');
}
return redirect('users');
}
Following is the code in view page
#extends('user.layout.app')
#section('content')
<script src="{{ url('js/user/location.js') }}"></script>
<div class="container-fluid add-location">
<div class="row">
<div class="col-md-12">
<div class="card">
<form method="post" action="{!! route('updateUsers', [$users->id]); !!}" name="useredit" id="useredit" enctype="multipart/form-data" novalidate>
{{ csrf_field() }}
<div class="card-header">
<h4 class="card-title"> Edit User </h4>
</div>
#if(!empty($errors->all()))
<div class="row"> #foreach ($errors->all() as $error)
<div class="col-lg-12">
<div class="alert alert-danger"> <span>{{ $error }}</span> </div>
</div>
#endforeach </div>
#endif
<div class="card-content">
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group">
<label class="control-label">Full Name
<star>*</star>
</label>
<input id="user_name" name="user_name" class="controls form-control" type="text" placeholder="User Name" value="{{$users->name}}">
#if ($errors->has('user_name')) <span class="help-block"> {{ $errors->first('user_name') }} </span> #endif </div>
</div>
<div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group{{ $errors->has('email') ? ' has-error' : '' }}">
<label for="email" class="control-label">Email
<star>*</star>
</label>
<input id="email" type="email" class="form-control" name="email" value="{{$users->email}}" placeholder="Email">
#if ($errors->has('email'))
<span class="help-block">
<strong>{{ $errors->first('email') }}</strong>
</span>
#endif
</div>
</div>
<!-- <div class="col-xs-12 col-sm-12 col-md-12">
<div class="form-group{{ $errors->has('password') ? ' has-error' : '' }}">
<label for="password" class="control-label">Password
<star>*</star>
</label>
<input id="password" type="password" class="form-control" name="password" value="{{bcrypt($users->password)}}">
#if ($errors->has('password'))
<span class="help-block">
<strong>{{ $errors->first('password') }}</strong>
</span>
#endif
</div>
</div> -->
</div>
<div class="row">
<div class="col-xs-12 col-sm-12 col-md-6">
<div class="col-xs-12 col-sm-12 col-md-12 form-action">
<button type="submit" class="btn btn-fill btn-info">Submit</button>
Cancel </div>
</div>
</form>
</div>
</div>
</div>
</div>
{!! $validator !!}
#endsection
What is the problem here, during adding customers, I am checking for email already exists, same is checking here also.
I don't know what is happening? Please help
try changing this line
$this->validate($request, [
'email' => 'required|email|max:255|unique:users' . $request->id
]);
to
$request->validate([
'email' => 'required|email|max:255|unique:users,email,'.$id
]);
Adding ',id' end of the statement which is used to prevent email exist check for the current id...
$request->validate([
'email' => 'required|email|max:255|unique:users,email,'.$request->id.',id',
]);
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?
I've been stuck on this issue for ages and I'm clueless on why it's not working, I've searched the internet and cannot find a solution. Whenever I register a user it just returns to /register no error. I can successfully php artisan migrate and it creates tables in my db in mysql.
Any help would be appreciated?
Routes:
Route::group(['middleware' => 'web'], function () {
Route::get('/', 'HomeController#index');
Route::auth();
});
Thanks.
Note: There is no error being displayed.
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 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
AuthController.php
<?php
namespace App\Http\Controllers\Auth;
use App\User;
use Validator;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
class AuthController extends Controller
{
/*
|--------------------------------------------------------------------------
| Registration & Login Controller
|--------------------------------------------------------------------------
|
| This controller handles the registration of new users, as well as the
| authentication of existing users. By default, this controller uses
| a simple trait to add these behaviors. Why don't you explore it?
|
*/
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
/**
* Where to redirect users after login / registration.
*
* #var string
*/
protected $redirectTo = '/';
/**
* Create a new authentication controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware($this->guestMiddleware(), ['except' => 'logout']);
}
/**
* 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, [
'name' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|min:6|confirmed',
]);
}
/**
* Create a new user instance after a valid registration.
*
* #param array $data
* #return User
*/
protected function create(array $data)
{
return User::create([
'name' => $data['name'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
}
Try to remove web middleware from routes.php if you're on 5.2.27 or higher.
Route::auth();
Route::get('/', 'HomeController#index');
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