Laravel validation doesn't seem to work at all - php

I am trying to validate the form data as they do in laravel's default authentication. It worked few days ago but now it doesn't work. If user didn't make any mistakes in form and submit it, then it successfully save data in the db. If user submit an empty form without any data or did some mistake in the form it's not showing the error message. If i add controller function code in a try catch, exception is showing as 'Invalid data'
view(form)
<form class="form-horizontal" action="{{ route('save-service-page-content') }}" method="POST" enctype="multipart/form-data">
<div class="box-body">
{{ csrf_field() }}
<div class="form-group{{ $errors->has('file') ? ' has-error' : '' }}">
<label for="image" class="col-sm-2 control-label">Service Image</label>
<input hidden id="service_image_file" name="file"/>
<div class="col-sm-10" id="demo-upload">
<div class="dropzone needsclick dz-clickable" id="serviceImageUpload">
<div class="dz-default dz-message">
<i class="fa fa-image fa-5x"></i>
<h3 class="sbold">Drop an image here to upload</h3>
<span>You can also click to open file browser</span>
</div>
</div>
#if ($errors->has('file'))
<span class="help-block"><strong>The service image is reuired</strong></span>
#endif
</div>
</div>
<div class="form-group{{ $errors->has('description') ? ' has-error' : '' }}">
<label for="inputEmail3" class="col-sm-2 control-label">Description</label>
<div class="col-sm-10">
<textarea rows="8" class="form-control" name="description" placeholder="Description goes here"></textarea>
#if ($errors->has('description'))
<span class="help-block"><strong>{{ $errors->first('description') }}</strong></span>
#endif
</div>
</div>
<div class="form-group{{ $errors->has('description_sin') ? ' has-error' : '' }}">
<label for="inputEmail3" class="col-sm-2 control-label">හැදින්වීම</label>
<div class="col-sm-10">
<textarea rows="8" class="form-control" name="description_sin" placeholder="හැදින්වීම සිංහලෙන්"></textarea>
<small class="form-text text-muted">හැදින්වීම ඇතුලත් කරන්න. (හැදින්වීම සිංහල බසින් ඇතුලත් කලොත් පමණක් එය ඉංග්‍රීසි බස වෙනුවට සිංහල බසින් දිස්වනු ඇත.)</small>
#if ($errors->has('description_sin'))
<span class="help-block"><strong>මෙම හැදින්වමෙහි අක්ෂර සහ ඉලක්කම් පමණක් ඇතුලත් විය යුතුය </strong></span>
#endif
</div>
</div>
</div>
<!-- /.box-body -->
<div class="box-footer clearfix">
<button type="submit" class="btn btn-default">Cancel</button>
<button type="submit" class="btn btn-info pull-right">Post</button>
</div>
</form>
Controller
namespace App\Http\Controllers;
use App\Service_page_content;
use App\Service;
use File;
use Image;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
class ServiceContent extends Controller
{
protected function validator(array $data)
{
return Validator::make($data, [
'file' => 'required',
'description' => 'nullable|alpha_num_spaces_brackets',
'description_sin' => 'nullable|alpha_num_spaces_brackets',
]);
}
public function save_page_content(Request $request)
{
$this->validator($request->all())->validate();
$service_page_content = new Service_page_content;
$service_page_content->description = $request->description;
$service_page_content->description_sin = $request->description_sin;
$file = $request->file;
$image_decode = base64_decode($file);
$image_data = base64_decode(preg_replace('#^data:image/\w+;base64,#i', '', $file));
$f = finfo_open();
$mime_type = finfo_buffer($f, $image_data, FILEINFO_MIME_TYPE);
$imageName = "service-page-content-".time().'.'.str_replace("image/","",$mime_type);
$image_resized = Image::make($image_data);
$image_resized->resize(1170, null, function ($constraint) {
$constraint->aspectRatio();
});
$image_resized->save(public_path("uploads/service_page_content_uploads/$imageName"));
$service_page_content->main_img_url = $imageName;
$service_page_content->save();
return redirect()->back()->with('success', ['Data Saved']);
}
}
I don't know if I'm doing it correctly on return Validator::make($data,...... or $this->validator($request->all())->validate();
I have written a custom validation rule that allows alpha numeric, spaces, brackets, '.' and ',' in AppServiceProvider boot function. It also worked few days ago. Now nothing seems to work.
It worked few days ago. Ignore the file upload part it is working perfectly I'm using Dropzone.js for it. May be I'm missing something. Any help would be appreciated !

You can validate directly on the array without calling the Validator facade.
protected function validator(Request $request)
{
return $request->validate([
'file' => 'required',
'description' => 'nullable|alpha_num_spaces_brackets',
'description_sin' => 'nullable|alpha_num_spaces_brackets',
]);
}
public function save(Request $request){
$this->validator($request);
}

Related

laravel 7 nothing happens when i click sign up button it seems like event is not triggering

hello and sorry for my bad English ,
can any one help me ? when i try to sign up nothing happens .
i use laravel 7.
every time I click the sign up button, nothing happens and also no errors are showing.
UserController.php
namespace App\Http\Controllers\Web\User;
use Reminder;
use Exception;
use Modules\User\Http\Controllers\AuthController;
class UserController extends AuthController
{
public $routes = [
'home' => 'web.home.index',
'forgot_password' => 'frontend.forgot.password',
'reset_password' => 'web.user.reset-password',
];
public function getLogin()
{
$return_url = '';
if ( request()->has('return-url') )
$return_url .= request()->input('return-url');
$data = [
'authenticate_url' => route('web.user.authenticate', ['return-url' => strip_tags(trim($return_url))])
];
return view('web.user.login', $data);
}
/**
* getNewAccount
*
* #return view
*/
public function getNewAccount()
{
return view('web.user.new-account')->with(['url' => route('web.user.post-new-account')]);
}
/**
* Logout current user.
*
* #return void
*/
public function getForgotPassword()
{
return view('web.user.forgot-password')->with(['url' => route('web.user.post-forgot-password')]);
}
/**
*
* getResetPassword()
*
* #return template
* #access public
**/
public function getResetPassword($userHashId,$reminderCode)
{
try {
$hashId = hasher($userHashId, true);
if ( !$hashId )
throw new Exception('Wrong user hash key, please check the url carefully.');
$user = $this->auth->findById($hashId);
$isReminderCodeExist = Reminder::exists($user);
if(!$isReminderCodeExist)
throw new Exception("Reset code is not exists, please retry.");
return view('web.user.reset-password')->with(['url' => route('web.user.post-reset-password'),
'code' => $reminderCode,
'hash_code' => $userHashId
]);
} catch (Exception $e) {
return redirect()->back()->withInput()->withErrors($e->getMessage());
}
}
}
new-account.blade.php
#extends( "layouts.master-login")
#section('content')
<div class="row no-gutters justify-content-center ">
<div class="hero-static col-sm-8 col-md-8 col-xl-8 d-flex align-items-center px-sm-0">
<div class="col-md-12 col-xl-10" style="margin: 0 auto;">
<div class="row no-gutters">
<div class="col-md-6 order-md-1 bg-white">
<div class="block-content block-content-full px-lg-5 py-md-5 py-lg-6">
<!-- Header -->
<div class="mb-2 text-center">
<p> #include('common.logo')</p>
<p class="text-uppercase font-w700 font-size-sm text-muted"> {{ __('dcm.new_account')}} </p>
</div>
<!-- END Header -->
<!-- Sign In Form -->
<form action="{{ $url }}" method="POST">
#if(session('error.message') )
<div class="form-group">
<span class="text-danger">{{ session('error.message') }}</span>
</div>
#endif
#csrf
<div class="form-group">
<input type="text" class="form-control form-control-alt {{ $errors->has('username') ? ' is-invalid' : '' }}" id="username-username" name="username" placeholder="{{ __('dcm.username_placeholder')}}">
{!! $errors->first('username', '<span class="text-danger">:message</span>') !!}
</div>
<div class="form-group">
<input type="text" class="form-control form-control-alt {{ $errors->has('email') ? ' is-invalid' : '' }}" id="email-email" name="email" placeholder="{{ __('dcm.email_placeholder')}}">
{!! $errors->first('email', '<span class="text-danger">:message</span>') !!}
</div>
<div class="form-group">
<input type="text" class="form-control form-control-alt {{ $errors->has('first_name') ? ' is-invalid' : '' }}" id="first_name-first_name" name="first_name" placeholder="{{ __('dcm.firstname_placeholder')}}">
{!! $errors->first('first_name', '<span class="text-danger">:message</span>') !!}
</div>
<div class="form-group">
<input type="text" class="form-control form-control-alt {{ $errors->has('last_name') ? ' is-invalid' : '' }}" id="last_name-last_name" name="last_name" placeholder="{{ __('dcm.lastname_placeholder')}}">
{!! $errors->first('last_name', '<span class="text-danger">:message</span>') !!}
</div>
<div class="form-group">
<input type="password" class="form-control form-control-alt {{ $errors->has('password') ? ' is-invalid' : '' }}" id="password" name="password" placeholder="{{ __('dcm.password_placeholder')}}">
{!! $errors->first('password', '<span class="text-danger">:message</span>') !!}
</div>
<div class="form-group">
<button type="submit" class="btn btn-block btn-hero-primary">
<i class="fas fa-plus mr-1"></i> {{ __('dcm.sign_up')}}
</button>
</div>
<hr/>
<div class="form-group">
<p class="mt-3 mb-0 d-lg-flex justify-content-lg-between">
<a class="btn btn-secondary btn-block d-block d-lg-inline-block mb-1" href="{{ route('web.user.index') }}" title="{{ __('dcm.sign_in')}}">
<i class="fa fa-fw fa-sign-in-alt mr-1"></i> {{ __('dcm.sign_in')}}
</a>
</p>
</div>
</form>
<!-- END Sign In Form -->
routes/web/user.php
<?php
// using this pattern to used php artisan route:cache,
// instead of using router closure/grouping.
$userRouteNameSpace = 'Web\User';
$middlewareName = 'dcm.logged.in';
// UserController
$userController = "{$userRouteNameSpace}\UserController";
// authenticate user
Route::get('user/login', "{$userController}#getLogin")->name('web.user.index');
Route::post('user/authenticate', "{$userController}#postAuthenticate")
->name('web.user.authenticate');
// logout user
Route::get('user/logout', "{$userController}#logout")
->name('web.user.logout');
// forgot password
Route::get('user/forgot-password', "{$userController}#getForgotPassword")
->name('web.user.forgot-password');
Route::post('user/forgot-password', "{$userController}#postForgotPassword")
->name('web.user.post-forgot-password');
// reset password
Route::get('user/reset-password/{hashId}/{resetcode}', "{$userController}#getResetPassword")
->name('web.user.reset-password');
Route::post('user/reset-password', "{$userController}#postResetPassword")
->name('web.user.post-reset-password');
// create new user account
Route::get('user/new-account', "{$userController}#getNewAccount")
->name('web.user.new-account');
Route::post('user/new-account', "{$userController}#postNewAccount")
->name('web.user.post-new-account');
// ProfileController
$profileController = "{$userRouteNameSpace}\ProfileController";
Route::get('user/profile', "{$profileController}#getProfile")
->name('web.user.profile')
->middleware($middlewareName);
Route::post('user/update-profile', "{$profileController}#postUpdateProfile")
->name('web.user.update.profile')
->middleware($middlewareName);
// update user avatar
Route::post('user/update-avatar/{hashId}', "{$profileController}#postUpdateAvatar")
->name('web.user.update.avatar')
->middleware($middlewareName);
// Verify User
Route::get('/verify','Auth\RegisterController#verifyUser')->name('verify.user');
When I click on sign up, nothing happens, it seems like event is not triggering
First
Please try to understand carefully, you have your both routes (GET route: get('user/new-account' for new-account page and POST route: post('user/new-account' for getting the values from new-account page) for creating a new user and they are ok. Don't change anything here:
// create new user account
Route::get('user/new-account', "{$userController}#getNewAccount")
->name('web.user.new-account');
Route::post('user/new-account', "{$userController}#postNewAccount")
->name('web.user.post-new-account');
Second
As you said, you don't have the method postNewAccount() in your userController so you must have one. So add this code inside your userController so that you can get the submitted data here:
public function postNewAccount(Request $request)
{
// you will get your submitted data here
// you can either dd() or return to see the submitted data
dd($request->all()); // or return $request->all();
// you can do the rest of the work here
}
If you successfully get data, then you can do next step like validation or storing data to database there.
Important note: your controller names start with small letter which is also problematic. So, change them like userController will be UserController
Suggestion:: Please follow the laravel documentation for better understanding the codes before trying them

Laravel form validation doesn't work when in my controller declaring more databases

I declare a variable containing the database so that the blade can select, but when doing so, the validation does not work. Please help me. Thank you very much.
this is the variable I call in the database to use select in the blade.
public function new_department(){
//return view('admin.new-department');
$manage_faculties=DB::table('faculties')->orderBy('id','asc')->get();
$all_manage_faculties=view('admin.new-department')->with('manage_faculties', $manage_faculties);
return view('layouts.master')->with('admin.new-department', $all_manage_faculties);
}
Here is the validation I use in the insert information and database.
public function save_new_department(Request $request){
$data = [];
$data['department_name'] = $request->input('department_name');
$data['description'] = $request->input('description');
$data['faculty_id'] = $request->input('faculty_name');
if($request->isMethod('post')){
$validator = Validator::make($request->all(), [
'department_name' => 'required|min:3|max:100|unique:departments',
'description' => 'required|max:500',
]);
if ($validator->fails()) {
return back()->with('toast_error', $validator->messages()->all()[0])->withInput();
}
DB::table('departments')->insert($data);
return redirect('/admin/departments/new')->withSuccess('Post Created Successfully!');
}
}
display it in the blade
After entering data whether it is true or false, it is not possible to report an error on the screen.After entering data whether it is true or false, it is not possible to report an error on the screen.
<form class="mt-3"method="post" action="{{ url('admin/department/new-department') }}">
{{csrf_field()}}
<div class="modal-content">
<div class="modal-header bg-primary">
<h5 class="modal-title">Create a Department</h5>
</div>
<!--end of modal head-->
<div class="modal-body">
<div class="form-group row align-items-center" {{ $errors->get('name') ? 'has-error' : '' }}>
<label class="col-2">Department</label>
<input class="form-control col" type="text" placeholder="Department name" name="department_name" required/>
#foreach($errors->get('name') as $error)
<span class="help-block">{{ $error }}</span>
#endforeach
</div>
<div class="form-group row align-items-center">
<label class="col-2">Faculty</label>
<select name="faculty_name" class="form-control col" required>
<option value="" selected>Select a Faculty</option>
#foreach($manage_faculties as $key => $cate_pro)
<option value="{{$cate_pro->id}}">{{$cate_pro->faculty_name}}</option>
#endforeach
</select>
</div>
<div class="form-group row">
<label class="col-2">Description</label>
<textarea class="form-control col" rows="10" placeholder="Write something here..." name="description" required ></textarea>
</div>
</div>
<!--end of modal body-->
<div class="modal-footer">
<button role="button" class="btn btn-primary" type="submit">
Post
</button>
</div>
</div>
</form>
You can look here for displaying errors in Laravel.
Why did you put :
{{ $errors->get('name') ? 'has-error' : '' }}
inside a "div" like a attribute ?

How can pdf be attached to mails in Laravel

I am trying to send a mail to a user but also want to attach a file to the mail. I am using the pdf package barryvdh/laravel-dompdf but I keep getting this error
Call to a member function attachData() on null at /app_path/app/Nova/Actions/SendAccountStatement.php:86)
This is my code
$data = [...];
$pdf = PDF::loadView('account-statement', $data);
// send account statement notification
Mail::to($model->email)
->bcc('another#mail.com')
->send(new StatementOfAccount($model)
->attachData($pdf->output(), "Account_Statement.pdf", ['mime' => 'application/pdf']);
The line throwing the error is ->attachData($pdf->output(), "Account_Statement.pdf", ['mime' => 'application/pdf'])
So from the error, I seem to missing something. What is the right way to attach a pdf file to the email?
app/Http/Controllers/TestController.php
namespace App\Http\Controllers;
use App\Mail\CheckUser;
use App\User;
use Carbon\Carbon;
use Illuminate\Http\Request;
use PDF;
class TestController extends Controller
{
public function index()
{
return view('welcome');
}
public function daily_report(Request $request)
{
$start_date = Carbon::parse($request->start_date)
->toDateTimeString();
$end_date = Carbon::parse($request->end_date)
->toDateTimeString();
$data['users'] = User::whereBetween('created_at',[$start_date,$end_date])->get();
$data['start_date'] = Carbon::parse($request->start_date)
->toDayDateTimeString();
$data['end_date'] = Carbon::parse($request->end_date)
->toDayDateTimeString();
$count = User::whereBetween('created_at',[$start_date,$end_date])->count();
if( $count < 1 ) {
session()->flash('message','There is no user between those date!');
return redirect()->back();
}
$pdf = PDF::loadView('test', $data, [
'format' => 'A4'
]);
\Mail::send('test', $data, function($message) use ($pdf){
$message->from('info#test.com*');
$message->to('mail#codechief.org');
$message->subject('Date wise user report');
$message->attachData($pdf->output(),'document.pdf');
});
$pdf->SetProtection(['copy', 'print'], '', 'pass');
return $pdf->stream('document.pdf');
}
}
One is for form and the other is our generated pdf file. So create it.
resources/views/welcome.blade.php
#extends('layouts.app')
#push('style')
<link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
#endpush
#section('content')
<div class="container">
<div class="row justify-content-center">
<div class="col-md-8">
#if(session()->has('message'))
<p class="btn btn-success btn-block btn-sm custom_message text-left" style="margin-top: 10px;">{{ session()->get('message') }}</p>
#endif
<legend>Search date wise user</legend>
<form action="{{ route('report') }}" method="get">
<div class="col-md-3">
<div class="form-group">
<label for="">Start Date</label>
<input type="date" class="form-control" name="start_date">
</div>
</div>
<div class="col-md-3">
<div class="form-group">
<label for="">End Date</label>
<input type="date" class="form-control" name="end_date">
</div>
</div>
<div class="col-md-2" style="margin-top: 24px;">
<div class="form-group">
<input type="submit" class="btn btn-primary" value="Submit">
</div>
</div>
</form>
</div>
</div>
</div>
#endsection

Laravel: File upload not working

I'm trying to upload an image via an HTML form in Laravel 5.5. I have included the enctype="multipart/form-data" attribute, still nothing happens.
Form code:
<form method="POST" enctype="multipart/form-data">
{{ csrf_field() }}
<div class="form-group">
<label for="m_photo" class="col-md-4 control-label">Main photo</label>
<div class="col-md-6">
<input id="m_photo" type="file" class="form-control-file space" name="m_photo" required>
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
Route (web.php) code:
Route::post('smartphones/entry', 'HomeController#s_submit')->name('s_submit');
Controller code:
public function s_submit() {
if (Input::hasFile('m_photo')) {
// doing something
}
else {
echo 'Nothing happened';
}
}
'Nothing happened' is echoed out when I submit the form.
It's interesting that when I do this:
public function s_submit(Request $request) {
$input = Input::all();
dd($input);
}
I see:
array:1 [
"m_photo" => UploadedFile {#210 ▶}
]
It's like the image is getting passed, but I'm unable to retrieve it. Please help.
This can happen when PHP max_file_size is not set to a size that allows the file you are trying to upload to be sent. This causes hasFile returns false, when, for example, file->getClientOriginalName() works.
Try to check upload_max_filesize or post_max_size in your php.ini, or try with a smaller file to check if it works.
if (Input::hasFile('m_photo')) {
$destinationPath = '/uploads/app/';
$file = $request->file('m_photo');
$filename = $file->getClientOriginalName();
$file->move(public_path() . $destinationPath, $filename);
$filename_to_save_in_db = $destinationPath . $filename;
}
Get the file with:
$file = $request->m_photo;
Or with:
$file = $request->file('m_photo');
https://laravel.com/docs/5.5/requests#retrieving-uploaded-files
You have forgot to put action in Your html Form :
put action="/smartphones/entry" or action="{{route('s_submit')}}"
<form method="POST" enctype="multipart/form-data" action="{{route('s_submit')}}">
{{ csrf_field() }}
<div class="form-group">
<label for="m_photo" class="col-md-4 control-label">Main photo</label>
<div class="col-md-6">
<input id="m_photo" type="file" class="form-control-file space" name="m_photo" required>
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
Create images folder in public folder
in your controller
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Storage;
public function s_submit(Request $request) {
if($request->hasFile('m_photo')){
$filenameWithExt=$request->file('m_photo')->getClientOriginalName();
$filename=pathinfo($filenameWithExt,PATHINFO_FILENAME);
$extension=$request->file('m_photo')->getClientOriginalExtension();
$fileNameToStore=$filename.'_'.time().'.'.$extension;
request()->m_photo->move(public_path('images'), $fileNameToStore);
}
else{
$fileNameToStore='noimage.jpg';
}
}
Try this:
public function s_submit()
{
request()->validate([
'm_photo' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:2048',
]);
$imageName = time().'.'.request()->m_photo->getClientOriginalExtension();
request()->m_photo->move(public_path('images'), $imageName);
return back()
->with('success','You have successfully upload image.')
->with('m_photo',$imageName);
}
Blade:
{!! Form::open(array('route' => 's_submit','files'=>true)) !!}
<div class="form-group">
<label for="m_photo" class="col-md-4 control-label">Main photo</label>
<div class="col-md-6">
{!! Form::file('m_photo', array('class' => 'form-control-file space')) !!}
</div>
</div>
<div class="form-group">
<div class="col-md-6 col-md-offset-4">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
{!! Form::close() !!}
For future visitors, the accepted answer is the right answer.
I wanted to share one more thing.
I also faced similar issue and I had set the upload_max_filesize and post_max_size variables to 20M, which was quite enough.
But I still faced the issue. So, I increased to 500M, then it worked.
It was really strange because I was uploading a file of less than 1 MB size.

Laravel admin login isn't working

Admin login don't work and don't give me any error.
I have this routes in web.php file:
Auth::routes();
Route::prefix('admin')->group(function () {
Route::get('/login','Auth\AdminLoginController#showLoginForm')->name('admin.login');
Route::post('/login','Auth\AdminLoginController#login')->name('admin.login.submit');
Route::get('/','AdminController#getIndex')->name('admin.dashboard');
Route::get('/logout','Auth\AdminLoginController#logout')->name('admin.logout');
Route::post('/password/email','Auth\AdminForgotPasswordController#sendResetLinkEmail')->name('admin.password.email');
Route::get('/password/reset','Auth\AdminForgotPasswordController#showLinkRequestForm')->name('admin.password.request');
Route::post('/password/reset','Auth\AdminResetPasswordController#reset');
Route::get('/password/reset/{token}','Auth\AdminResetPasswordController#showResetForm')->name('admin.password.reset');
});
And this functions in controller(I only put here which have the problems)
public function showLoginForm()
{
return view('auth.adminlogin');
}
public function login(Request $request)
{
//validate the form data
$this->validate($request, [
'email' => 'required|email',
'password' => 'required|min:6'
]);
//attempt to log the user in
if (Auth::guard('admin')->attempt(['email' => $request->email, 'password' => $request->password], $request->remember)){
//if successful, then redirect to their intended location
return redirect('/admin');
}
return redirect()->back()->withInput($request->only('email','remember'));
}
And in resources/views/auth/adminlogin.blade.php i have this code:
#extends('backend.public.includes.head')
<body>
<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 Login</div>
<div class="panel-body">
<form class="form-horizontal" role="form" method="POST" action="{{ route('admin.login.submit') }}">
{{ 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('admin.password.request') }}">
Forgot Your Password?
</a>
</div>
</div>
</form>
</div>
</div>
</div>
</div>
</div>
</body>
This was working days ago.. and now not, i'm looking all but don't find the error. In networking isn't showing anything and with a debug i don't see anything.
I try to reset password and when i reset it (i have a redirect in the function he redirect me good, only not working in normal login).
Errors aren't showed too
EDIT
Migrate file:
public function up()
{
Schema::create('admins', function (Blueprint $table) {
$table->increments('id');
$table->string('name',50)->unique();
$table->string('email',200)->unique();
$table->string('password');
$table->boolean('public')->default(true);
$table->rememberToken();
$table->timestamps();
});
}
Seed file:
private $arrayAdmins = array(
array(
'name' => 'Lluis',
'email' => 'lluis.puig#correo.biz',
'password' => 'correo1',
'public' => 1
)
);
public function run()
{
self::seedAdmins();
}
public function seedAdmins()
{
DB::table('admins')->delete();
foreach ($this->arrayAdmins as $admin)
{
$a = new Admin;
$a->name = $admin['name'];
$a->email = $admin['email'];
$a->password = $admin['password'];
$a->public = $admin['public'];
$a->save();
}
}
The admin login isn't working if i created with the seed. (So the problem i guess is with the "user created" with the seed.
I try to create one with php artisan tinker and it works.
SOLVED
I check the seed. The problem was de password isn't encrypted!
This line :
$a->password = $admin['password'];
Must be like this:
$a->password = bcrypt($admin['password']);

Categories