Laravel can't render view with form and token - php

I'm trying to render the view with the form reset password and laravel can't do it. Don't have errors but view is all white. If i change the view to other with a simple h1 laravel render it.
So, I guess the problem is with the token.
The route is this:
Route::get('/password/reset/{token}','Auth\AdminResetPasswordController#showResetForm')->name('admin.password.reset');
The controller function this:
public function showResetForm(Request $request, $token = null)
{
return view('auth.passwords.reset-admin')->with(
['token' => $token, 'email' => $request->email]
);
}
And the view file is at
/resources/views/auth/passwords/reset-admin.blade.php
Thanks a lot.
At the end of the render process execute this function:
public function handleShutdown()
{
if (! is_null($error = error_get_last()) && $this->isFatal($error['type'])) {
$this->handleException($this->fatalExceptionFromError($error, 0));
}
}
Blade content:
#extends('backend.public.includes.head')
#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">ADMIN Reset Password</div>
<div class="panel-body">
#if (session('status'))
<div class="alert alert-success">
{{ session('status') }}
</div>
#endif
<form class="form-horizontal" role="form" method="POST" action="{{ route('admin.password.request') }}">
{{ csrf_field() }}
<input type="hidden" name="token" value="{{ $token }}">
<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="{{ $email or old('email') }}" required autofocus>
#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{{ $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" required>
#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">
Reset Password
</button>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
#endsection
Extrainfo:
Take the scripts, but not render the form.
Error on error.loc
2017/07/14 11:19:35 [error] 5048#5048: *1 FastCGI sent in stderr: "PHP message: PHP Warning: require(/home/vagrant/Code/name/bootstrap/../vendor/autoload.php): failed to open stream: No such file or directory in /home/vagrant/Code/name/bootstrap/autoload.php on line 17
PHP message: PHP Stack trace:
PHP message: PHP 1. {main}() /home/vagrant/Code/name/public/index.php:0
PHP message: PHP 2. require() /home/vagrant/Code/name/public/index.php:22
If i put something like alskdaslkd on the view, it render it.
SOLVED
The problem is i use extend to head (where i have all the scripts) but in /layouts/default is where i define my "structure" with #yield('content') so if i put #extends('backend.public.layouts.default') on the top of the blade, i can use #section('content')

Related

Laravel- Show errors on the login page when login credentials are wrong

I am new to Laravel. I am designing an login page and I want to show the errors on login page itself when the login credentials are wrong. I haven't done anything in controller. I am using the inbuilt Laravel function-Auth. Here is my view code given below:
<div class="card">
<div class="card-header">{{ __('Login') }}</div>
<div class="card-body">
<form method="POST" action="{{ route('login') }}" aria-label="{{ __('Login') }}">
#csrf
<div class="form-group row">
<label for="email" class="col-sm-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>
<div class="col-md-6">
<input id="email" type="email" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}" name="email" value="{{ old('email') }}" required autofocus>
#if ($errors->has('email'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('email') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group row">
<label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</label>
<div class="col-md-6">
<input id="password" type="password" class="form-control{{ $errors->has('password') ? ' is-invalid' : '' }}" name="password" required>
#if ($errors->has('password'))
<span class="invalid-feedback" role="alert">
<strong>{{ $errors->first('password') }}</strong>
</span>
#endif
</div>
</div>
<div class="form-group row">
<div class="col-md-6 offset-md-4">
<div class="checkbox">
<label>
<input type="checkbox" name="remember" {{ old('remember') ? 'checked' : '' }}> {{ __('Remember Me') }}
</label>
</div>
</div>
</div>
<div class="form-group row mb-0">
<div class="col-md-8 offset-md-4">
<button type="submit" class="btn btn-primary">
{{ __('Login') }}
</button>
<a class="btn btn-link" href="{{ route('password.request') }}">
{{ __('Forgot Your Password?') }}
</a>
</div>
</div>
</form>
</div>
Controller Redirection:
Redirect::back()->withErrors(['errormsg', 'Try Again']);
Blade file:
#if($errors->any())
<h4>{{$errors->first()}}</h4>
#endif
Use this code and check.
if(Auth::attempt($user_data))
{
return redirect('/');
}
else
{
return redirect()->back()->withErrors(['error','Wrong Login Details']);
}
and put this code in login blade file.
#if($errors->any())
<h4>{{$errors->first()}}</h4>
#endif

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

How to send login errors back without any redirect ? Laravel 5.4

In the Laravel code: AuthenticatesUsers.php there's this function that returns error messages back to the user, for example if they didn't enter a registered email address:
protected function sendFailedLoginResponse(Request $request)
{
$errors = [$this->username() => trans('auth.failed')];
if ($request->expectsJson()) {
return response()->json($errors, 422);
}
return redirect()->back()
->withInput($request->only($this->username(), 'remember'))
->withErrors($errors);
}
My issue is that I'm using a Modal box so when this function redirects to the same page the modal disappears and the user can only see the errors when he clicks to see the modal again.
How can I send the data back without using redirect() or any refresh ?
This is the AJAX call I'm using:
<script type="text/javascript">
$(function(){
$('#login').click(function(e) {
e.preventDefault();
$('#myModal').modal();
});
$(document).on('submit', '#formLogin', function(e) {
e.preventDefault();
$.ajax({
method: $(this).attr('method'),
url: $(this).attr('action'),
data: $(this).serialize(),
dataType: "json"
})
.done(function(data) {
console.log(data);
})
.fail(function(data) {
console.log(data);
});
});
})
</script>
For completion, this is the entire Modal with both the registration and login forms:
<!-- Modal -->
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel">recharge.ae | Welcome!</h4>
</div>
<div class="modal-body">
<div id="reg-div">
<h4>New customer? Register below.</h4>
<form class="form-horizontal" method="POST" action="{{ route('register') }}" id="formRegister">
{{ 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>
{{-- <small class="help-block"></small> --}}
#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-reg" type="email" class="form-control" name="email" value="{{ old('email') }}" required>
{{-- <small class="help-block"></small> --}}
#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>
{{-- <small class="help-block"></small> --}}
#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 and Log Me In
</button>
</div>
</div>
</form>
</div><!--#reg-div-->
<div id="login-div">
<h4>Returning customer? Login below.</h4>
<form class="form-horizontal" method="POST" action="{{ route('login') }}" id="loginForm">
{{ csrf_field() }}
<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 autofocus>
#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">
<div class="col-md-6 col-md-offset-4">
<div class="checkbox">
<label>
<input type="checkbox" name="remember" {{ old('remember') ? 'checked' : '' }}> Remember Me
</label>
</div>
</div>
</div>
<div class="form-group">
<div class="col-md-8 col-md-offset-4">
<button type="submit" class="btn btn-primary">
Login
</button>
<a class="btn btn-link" href="{{ route('password.request') }}">
Forgot Your Password?
</a>
</div>
</div>
</form>
</div><!-- #login-div -->
</div>
</div>
</div>
</div>
Well, return a JSON response rather than redirecting the page. Here's how to do it. Rather than this
return redirect()->back()
->withInput($request->only($this->username(), 'remember'))
->withErrors($errors);
write this
return json_encode([ 'errorr' => $$errors ]);
and via above line, you get the data in the done function of the ajax. There you just need to parse that JSON like this
data = JSON.parse(data);
and then you can access the errors like this data.errors but here you need to keep one thing in mind you will need to attach these errors in the html yourself
P.S If there is anything that you don't understand feel free to ask

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

Laravel 5.2: How to add a register page?

I am using Laravel 5.2,
and I use php artisan make:auth to make register page and login page.
Now, I would want to make two separated register pages,which used by two roles,seller and buyer ,
the two register pages named seller-register.blade.php and buyer-register.blade.php,
in view,add a item named userType,respectively corresponding seller and buyer,like this:
seller-register.blade.php
<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('/seller-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">
<label class="col-md-4 form-control-label">User Type</label>
<div class="col-md-6">
<label class="c-input c-radio">
<input id="userType" name="userType" type="radio" value="1" checked>
<span class="c-indicator"></span>
seller
</label>
</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>
Question:
How to modify controller and other something?

Categories