livewire validation is working real-time message "required.validation" show this Problem - laravel-livewire

livewire validation is working real-time message show "required.validation" but I see the display message "first_name field is required"
This is my livewire component code
public $first_name = '';
public $last_name = '';
public $email = '';
public $phone_number = '';
public $password = '';
public $password_confirmation = '';
public $business_name = '';
public $comments = '';
public $solutions_of_interest = '';
protected $rules = [
'first_name' => 'required',
'first_name' => 'required|max:255',
'last_name' => 'required|max:255',
'phone_number' => 'required|digits:9',
'business_name' => 'required|max:255',
'solutions_of_interest' => 'required|max:255',
'email' => 'required|email|unique:users',
'password' => 'required|min:8|confirmed',
'password_confirmation' => 'required|min:8',
];
public function save()
{
$this->validate();
User::create([
'first_name' => $this->first_name,
'last_name' => $this->last_name,
'email' => $this->email,
'phone_number' => $this->phone_number,
'password' => Hash::make($this->password),
'business_name' => $this->business_name,
'comments' => $this->comments,
'solutions_of_interest' => $this->solutions_of_interest,
'email_verified_at' => Carbon::now(),
'phone_number_varified' => 1,
]);
// $this->reset();
session()->flash('success','User Created Successfully.');
}
public function updated($property)
{
$this->validateOnly($property);
}
this is my livewire blade component code
<div class="col-xl-6 col-lg-6 col-md-6 col-sm-6 col-12">
<input type="text" class="form-control" wire:model="first_name"
autocomplete="first_name" autofocus placeholder="First Name">
#error('first_name') <span class="text-danger">{{ $message }}</span>#enderror
</div>
<div class="col-xl-6 col-lg-6 col-md-6 col-sm-6 col-12">
<input type="text" class="form-control" wire:model="last_name"
autocomplete="last_name" autofocus placeholder="Last Name">
#error('last_name')
<span class="text-danger">{{ $message }}</span>
#enderror
</div>
see this image
enter image description here

can you try customize your validation messages:
https://laravel-livewire.com/docs/2.x/input-validation#customize-error-message-and-attributes

Related

How to fix "net::ERR_CONNECTION_REFUSED and Error: Network Error" error in Reactjs,Django,Django Rest Frame work project

I am trying pass data from reactjs to django through django rest api by post method but there raising this problem.
I have tested post method through Django-REST Api GUI.It's working perfectly.
My Reactjs component code:
import React, { Component } from 'react'
import './Register.css';
import axios from 'axios'
const REGISTER_URL = 'http://127.0.0.1:8000/api/register/?format=json' // received api ulr...
const initiaState = {
username : '',
email : '',
password: ''
}
class Register extends Component{
constructor(){
super()
this.myRegister = React.createRef()
}
state = {
...initiaState
}
changeHandler = (event) => {
this.setState({
[event.target.name]: event.target.value
})
}
submitHandler = (event) =>{
event.preventDefault()
console.log(this.state)
this.myRegister.current.reset()
this.setState({
...initiaState
});
axios.post(REGISTER_URL,this.state)
.then(res =>{
console.log(res)
})
.catch(error =>{
console.log("ERROR::: "+error)
})
}
render(){
return(
<div className="Register-box">
<form ref = {this.myRegister} className="Form" onSubmit={this.submitHandler }>
<div className ="form-group ">
<label htmlFor="username" > Name: </label>
<input
className = "from-control ml-4"
type="text"
placeholder = ' Enter Your Name '
name = "username"
id = "username"
value = {this.state.name}
onChange = {this.changeHandler}
/>
</div>
<div className ="form-group">
<label htmlFor="email" > Email: </label>
<input
className = "from-control ml-4"
type="text"
placeholder = ' Enter Your Email '
name = "email"
id = "email"
value = {this.state.email}
onChange = {this.changeHandler}
/>
</div>
<div className ="form-group">
<label htmlFor="password" className="mr-4"> Password: </label>
<input
className = "from-control ml-2"
type="password"
placeholder = ' Enter Your Password '
name = "password"
id = "password"
value = {this.state.password}
onChange = {this.changeHandler}
/>
</div>
<button className = "btn btn-primary" type="submit" value="Submit"> Submit </button>
</form>
</div>
);
}
}
export default Register;
The error is the server connection error. Make sure you have run your server properly.
Check your IP address is correct or not
As you are running your Django server as debugging/testing mode. Run your server using python manage.py runserver 0.0.0.0:8000 here 8000 is the port number.

Laravel 5.5 The email and password field is required

I am new and installed Laravel 5.5 and trying to work on login functionality. I am using custom fields to login; user_name and user_password. When I submit I am getting
The email field is required.
The password field is required.
but my fields are user_name and user_password in the user table
Login controller
namespace App\Http\Controllers\Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Illuminate\Support\Facades\Session;
class LoginController extends Controller
{
use AuthenticatesUsers;
protected $redirectAfterLogout = '/';
/**
* Create a new controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('guest', ['except' => 'logout']);
}
/**
* Logout, Clear Session, and Return.
*
* #return void
*/
public function logout()
{
$user = Auth::user();
Log::info('User Logged Out. ', [$user]);
Auth::logout();
Session::flush();
return redirect(property_exists($this, 'redirectAfterLogout') ? $this->redirectAfterLogout : '/');
}
protected function getCredentials(Request $request){
return $request->only('user_name', 'user_password');
}
}
View
#extends('layouts.app')
#section('content')
<div class="container">
<div>
<a class="hiddenanchor" id="signup"></a>
<a class="hiddenanchor" id="signin"></a>
<div class="login_wrapper">
<div class="animate form login_form">
<section class="login_content">
<form class="form-horizontal" role="form" method="POST" action="{{ route('login') }}">
{{ csrf_field() }}
<h1>Login Form</h1>
<div>
<input id="email" type="email" class="form-control" name="user_name" value="{{ old('user_name') }}" required autofocus>
</div>
<div>
<input id="password" type="password" class="form-control" name="user_password" required>
</div>
<div>
<button type="submit" name="login" class="btn btn-default submit">Log in</button>
<a class="reset_pass" href="#">Lost your password?</a>
</div>
<div class="clearfix"></div>
<div class="separator"></div>
</form>
</section>
</div>
</div>
</div>
You are using the trait AuthenticatesUsers and it is responsible for validating the data after the user submitted the form. If you take a look at this file, you will see this method:
/**
* Validate the user login request.
*
* #param \Illuminate\Http\Request $request
* #return void
*/
protected function validateLogin(Request $request)
{
$this->validate($request, [
$this->username() => 'required|string',
'password' => 'required|string',
]);
}
More specifically, as you can see, this method is in charge for calling the validator on the fields name "password" and by the method username(). If you only wanted to custom the username field, you could overwrite the username() method in LoginController class:
public function username()
{
return 'user_name';
}
But since you want to custom both the username field name and the password field name, I suggest that you overwrite the validateLogin() method in the LoginController class:
protected function validateLogin(Request $request)
{
$this->validate($request, [
'user_name' => 'required|string',
'user_password' => 'required|string',
]);
}
Hope that helps.
You must go to app/User.php and change
protected $fillable = [
'name', 'email', 'password',
];
to
protected $fillable = [
'name', 'user_email', 'user_password',
];
It will solve your problem. But i must suggest to you change your view form field to email, password instead of user_name, user_password

Sending mail using Laravel 4.2 and Mailgun

i'm little bit new to this.
I had read the documentation of Laravel 4 and some of the Mailgun, I had tested some mail and worked but just in route like this:
Route::get('send_test_email', function(){
Mail::send('emails.registro', array('key' => 'value'), function($message)
{
$message->subject('Bienvenido a la gran experiencia');
$message->from(env('CONTACT_MAIL'), env('CONTACT_NAME'));
$message->to('luis02lopez#hotmail.com');
});
});
I went to myapp/send_test_email in the browser and get an email.
But now I want to send an email at registration, I created the route:
Route::get('mail', ['uses' => 'MailController#send', 'as' => 'send']);
The controller:
<?php
class MailController extends \BaseController {
public function index()
{
return View::make('signup');
}
public function send() {
Mail::send('emails.registro', $data, function($message) use
           {
           $message->subject('Bienvenido a la gran experiencia');
           
           $message->from(env('CONTACT_MAIL'), env('CONTACT_NAME'));
           
           $message->to($user->email, $user->firstname);
           });
}
And added a form to the signup form like this:
{{ Form::open(['route' => 'send', 'method' => 'get']) }}
<div class="form-group">
{{ Form::label('username', 'Usuario', ['class' => 'sr-only']) }}
{{ Form::text('username', null, ['placeholder' => 'Usuario', 'required', 'minlength' => 6, 'class' => 'form-control', ]) }}
#foreach($errors->get('username', '<span class=error>:message</span>') as $message)
{{$message}}
#endforeach
</div>
<div class="form-group">
{{ Form::label('password', 'Contraseña', ['class' => 'sr-only']) }}
{{ Form::password('password', ['placeholder' => 'Contraseña', 'required', 'minlength' => 8, 'class' => 'form-control']) }}
#foreach($errors->get('password', '<span class=error>:message</span>') as $message)
{{$message}}
#endforeach
</div>
<div class="form-group">
{{ Form::label('password_confirm', 'Confirmar Contraseña', ['class' => 'sr-only']) }}
{{ Form::password('password_confirmation', ['placeholder' => 'Confirmar Contraseña', 'required', 'minlength' => 8, 'class' => 'form-control']) }}
#foreach($errors->get('password_confirmation', '<span class=error>:message</span>') as $message)
{{$message}}
#endforeach
</div>
<div class="form-group">
{{ Form::label('email', 'Email', ['class' => 'sr-only']) }}
{{ Form::email('email', null, ['placeholder' => 'Email', 'required', 'class' => 'form-control']) }}
#foreach($errors->get('email', '<span class=error>:message</span>') as $message)
{{$message}}
#endforeach
</div>
<div class="form-group">
{{ Form::label('firstname', 'Nombres', ['class' => 'sr-only']) }}
{{ Form::text('firstname', null, ['placeholder' => 'Nombres', 'required', 'class' => 'form-control']) }}
</div>
<div class="form-group">
{{ Form::label('lastname', 'Apellidos', ['class' => 'sr-only']) }}
{{ Form::text('lastname', null, ['placeholder' => 'Apellidos', 'required', 'class' => 'form-control']) }}
</div>
<div class="form-group">
{{ Form::submit('Registrar', ['class' => 'btn btn-lg btn-block btn-kinbu'])}}
</div>
{{ Form::close() }}
And I got a Parse error: syntax error, unexpected 'Mail' (T_STRING) in the controller, why?
Here I have errors:
public function send() {
Mail::send('emails.registro', $data, function($message) use
{
$message->subject('Bienvenido a la gran experiencia');
$message->from(env('CONTACT_MAIL'), env('CONTACT_NAME'));
$message->to($user->email, $user->firstname);
});
}
I'm using the $user var, but I'm not passing it with the closure "user" so I have to do:
public function send() {
Mail::send('emails.registro', array('key' => 'value'), function($message) use ($user)
{
$message->subject('Bienvenido a la gran experiencia');
$message->from(env('CONTACT_MAIL'), env('CONTACT_NAME'));
$message->to($user->email, $user->firstname);
});
}

NotFoundHttp Exception (Controller Method Not Found )- Laravel 5.1 Facebook Login

I am integrating Facebook Login in my New Laravel 5.1.The user will have the option to manually login by using Facebook Login or the traditional form login.So far I have no problem implementing traditional login
For the Laravel Socialite, I think I already set correctly
composer.json
"laravel/socialite": "^2.0",
config/app.php
'providers' => [
/*
* Laravel Framework Service Providers...
*/
.........
.........
Illuminate\Html\HtmlServiceProvider::class,
/*
* Application Service Providers...
*/
App\Providers\AppServiceProvider::class,
App\Providers\AuthServiceProvider::class,
App\Providers\EventServiceProvider::class,
App\Providers\RouteServiceProvider::class,
Laracasts\Flash\FlashServiceProvider::class,
Laracasts\Generators\GeneratorsServiceProvider::class,
AlgoliaSearch\Laravel\AlgoliaServiceProvider::class,
Laravel\Socialite\SocialiteServiceProvider::class,
],
AuthController
<?php
namespace App\Http\Controllers\Auth;
use Socialite;
//use Illuminate\Routing\Controller;
use App\User;
use Validator;
use Auth;
use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\ThrottlesLogins;
use Illuminate\Foundation\Auth\AuthenticatesAndRegistersUsers;
class AuthController extends Controller
{
use AuthenticatesAndRegistersUsers, ThrottlesLogins;
protected $redirectTo = '/admin';
/**
* Create a new authentication controller instance.
*
* #return void
*/
public function __construct()
{
$this->middleware('guest', ['except' => 'getLogout']);
}
//temporarily redirected to duterte-run.mendanielle.com
public function getRegister()
{
return view('auth.login');
}
/**
* 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, [
'username' => 'required|max:255',
'email' => 'required|email|max:255|unique:users',
'password' => 'required|confirmed|min:6',
]);
}
/**
* Create a new user instance after a valid registration.
*
* #param array $data
* #return User
*/
protected function create(array $data)
{
return User::create([
'firstname' => $data['firstname'],
'lastname' => $data['lastname'],
'username' => $data['username'],
'email' => $data['email'],
'password' => bcrypt($data['password']),
]);
}
/**
* Redirect the user to the GitHub authentication page.
*
* #return Response
*/
public function redirectToProvider()
{
return Socialite::driver('facebook')->redirect();
}
/**
* Obtain the user information from GitHub.
*
* #return Response
*/
public function handleProviderCallback()
{
// try {
$user = Socialite::driver('facebook')->user();
// } catch (Exception $e) {
// return redirect('auth/facebook');
// }
// $authUser = $this->findOrCreateUser($user);
// Auth::login($authUser, true);
// return redirect()->route('home');
}
routes.php
Route::get('/auth/facebook', 'Auth\AuthController#redirectToProvider');
Route::get('/auth/facebook/callback', 'Auth\AuthController#handleProviderCallback');
// Logging in and out
get('/auth/login', 'Auth\AuthController#getLogin');
post('/auth/login', 'Auth\AuthController#postLogin');
get('/auth/logout', 'Auth\AuthController#getLogout');
login form
<form class="form-horizontal" role="form" method="POST" action="{{ url('/auth/login') }}">
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="form-group">
<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') }}">
</div>
</div>
<div class="form-group">
<label class="col-md-4 control-label">Password</label>
<div class="col-md-6">
<input type="password" class="form-control" name="password">
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<div class="checkbox">
<label><input type="checkbox" name="remember"> Remember Me</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">Login</button>
<a class="btn btn-link" href="{{ url('/password/email') }}">Forgot Your Password?</a>
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<a class="btn btn-link" href="{{ url('/auth/facebook') }}">Login With Facebook</a>
</div>
</div>
</form>
I followed the latest documentation at Laravel.com website,and inside services.php
'facebook' => [
'client_id' => env('FACEBOOK_CLIENT_ID'),
'client_secret' => env('FACEBOOK_CLIENT_SECRET'),
'redirect' => env('CALL_BACK_URL'),
],
And the .env file
FACEBOOK_CLIENT_ID=1834566497828637244
FACEBOOK_CLIENT_SECRET=9505676d1f50bty7b613baa7b68786op5ba48
CALL_BACK_URL=http://localhost:9090/auth/login
The login button will redirect me to
localhost:9090/auth/facebook
NotFoundHttpException in Controller.php line 269:
Controller method not found.
at Controller->missingMethod('facebook')
at call_user_func_array(array(object(AuthController), 'missingMethod'), array('_missing' => 'facebook')) in Controller.php line 256
at Controller->callAction('missingMethod', array('_missing' => 'facebook')) in ControllerDispatcher.php line 164
at ControllerDispatcher->call(object(AuthController), object(Route), 'missingMethod') in ControllerDispatcher.php line 112
at ControllerDispatcher->Illuminate\Routing{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 139
at Pipeline->Illuminate\Pipeline{closure}(object(Request)) in RedirectIfAuthenticated.php line 41
So what's the proper way? How do you integrate Socialite in Laravel 5.1?
update
I see this 'weird' result in php artisan route:list
GET|HEAD|POST|PUT|PATCH|DELETE | auth/{_missing} | App\Http\Controllers\Auth\AuthController#missingMethod | guest |
Just under the
| auth/facebook|App\Http\Controllers\Auth\AuthController#redirect
Got it
In controller, instead of
use App\Http\Controllers\Controller;
This is the correct controller
use Illuminate\Routing\Controller;
And I fixed the routes,
Route::get('/auth/facebook/callback','Auth\AuthController#handleProviderCallback');
Should match the call back_url listed in .env file which is
http://localhost:9090/admin
So to correct this
Route::get('/admin','Auth\AuthController#handleProviderCallback');
Needs some tweaks when saving if the user is not listed in database but it works when a registered user logs

Angular and Rails not able to create a user with the data sent

I have a Rails 4 api with devise gem with an angular frontend. When i send a user json object the post parameters are sent but rails doesn't seem to like the format:
The Json object sent from the angular to the rails api is:
Resource {first_name: "test first", last_name: "test last", email: "test#test.com", password: "testpass", password_confirmation: "testpass"}
but the data is received by rails as:
Parameters: Parameters: {"first_name"=>"test first", "last_name"=>"test last", "email"=>"test#test.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]", "user"=>{"email"=>"test#test.com", "first_name"=>"test first", "last_name"=>"test last"}}
and fails on the validation: ["Password can't be blank"]. Which shows it expects the user object format, but why isn't the password and password confirmation being added here?
I'm not sure whether i'm doing something wrong with Angular or Rails. If i send a request from Angular formatted as:
$scope.user = new User({user: {first_name: 'test first',
last_name: 'test last',
email: 'test#test.com',
password: 'testpass',
password_confirmation: 'testpass'}});
then this works:
SQL (0.7ms) INSERT INTO "users" ("created_at", "email", "encrypted_password", "first_name", "last_name", "updated_at") VALUES (?, ?, ?, ?, ?, ?) [["created_at", Sun, 29 Jun 2014 11:25:47 UTC +00:00], ["email", "test#test.com"], ["encrypted_password", "$2a$10$p70dQldL.b1SnyQFacr9YechtPOxLLNCjyuawiY/iPJGu4YgoQYV."], ["first_name", "test first"], ["last_name", "test last"], ["updated_at", Sun, 29 Jun 2014 11:25:47 UTC +00:00]]
but $scope.user = new User(); doesn't. Here is my code:
Users angular controller:
angular
.module('app')
.controller('UsersCtrl', ['User', '$scope', '$route', function(User, $scope, $route) {
$scope.user = new User();
$scope.users = User.query();
$scope.save = function() {
$scope.user.$save();
$scope.users.push($scope.user);
$scope.user = new User();
};
}]);
Angular users service
angular
.module('app')
.factory('User', function($resource) {
var User = $resource('http://0.0.0.0:3000/api/v1/users/:id.json', {id: '#id'}, {
update: {
method: 'PUT'
}
});
return User;
});
user rails controller
def new
respond_with(User.new)
end
def create
#user = User.new(user_params)
if #user.save
render :json => { :success => true }
else
Rails.logger.debug #user.errors.full_messages
render :json => { :errors => #user.errors.full_messages }, :status => :unprocessable_entity
end
end
private
def user_params
params.require(:user).permit(:first_name, :last_name, :email, :password, :password_confirmation)
end
angular view
<form class="form-horizontal" ng-submit="save(user)">
<div class="control-group">
<label class="control-label" for="inputFirstName">First Name:</label>
<div class="controls">
<input type="text" id="inputFirstName" ng-model="user.first_name"/>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputLastName">Last Name:</label>
<div class="controls">
<input type="text" id="inputLastName" ng-model="user.last_name"/>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputEmail">Email:</label>
<div class="controls">
<input type="text" id="inputEmail" ng-model="user.email"/>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPassword">Password:</label>
<div class="controls">
<input type="text" id="inputPassword" ng-model="user.password"/>
</div>
</div>
<div class="control-group">
<label class="control-label" for="inputPasswordConfirmation">Password Confirmation:</label>
<div class="controls">
<input type="text" id="inputPasswordConfirmation" ng-model="user.password_confirmation"/>
</div>
</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn btn-primary">Create user</button>
</div>
</div>
</form>