Reputation: 419
I'm using Laravel
with Nginx
, PHP 7.1
and Ubuntu 18
.
I have a login form as follows:
Login.blade.php:
{!! Form::open(['action' => 'LoginController@login'],['class' => 'form'])!!}
<h2 style="text-align: center;">{{__("Login to your account")}}</h2>
{!! Form::text('timezone', null,
array('style'=>'display:none',
'class'=>'form-control',
'id'=>'timezone',
'placeholder'=>__('timezone'))) !!}
{!! Form::text('pushToken', null,
array('style'=>'display:none',
'class'=>'form-control',
'id'=>'pushToken',
'placeholder'=>__('Token'))) !!}
{!! Form::text('email', null,
array('required',
'class'=>'form-control',
'placeholder'=>__('Email'))) !!}
{!! Form::password('password',
array('required','placeholder' => __('Password'))) !!}
{!! Form::checkbox('remember_me', null, null, array(
'class'=>'checkbox',
'style'=>'width: fit-content; display: inline-block'
))!!}{{__("Remember Me")}}
{!! Form::Submit(__('Login'), null,
array(
'class'=>'form-control'
)) !!}
{!! Form::close() !!}
In my controller when I try to check the values of email
and password
, they are always empty. Knowing that when I test on ubuntu 16.04
everything is fine
Controller Code:
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\App;
use Request as Req;
use Session;
use Cookie;
use Config;
use Redirect;
class LoginController extends Controller
{
public function login(Request $request)
{
$email = Req::input('email');
$password = Req::input('password');
echo $email;
}}
Composer.json
"require": {
"php": ">=5.6.4",
"guzzlehttp/guzzle": "^6.2",
"laravel/framework": "5.5.*",
"laravel/tinker": "~1.0",
"laravelcollective/html": "^5.4",
"maatwebsite/excel": "~2.1.0",
"mariuzzo/laravel-js-localization": "^1.4",
"nesbot/carbon": "^1.25",
"symfony/psr-http-message-bridge": "^1.0"
},
Upvotes: 1
Views: 7936
Reputation: 316
Many times it happens that there are problems in the .htaccess file.
By default laravel comes with a ModRewrite rule that redirects everything that is not a file, or folders, to index.php, but ami never ends up working well ... so I correct it every time I do a project. I change the syntax a little bit to capture everything but with (. *) And very important to re-transmit the QueryString of the GET requests is the keyword "QSA" that I add after "L" (last rule)
in my case I leave the rule like this:
# Handle Front Controller ...
RewriteCond %{REQUEST_FILENAME} !-D
RewriteCond %{REQUEST_FILENAME} !-F
RewriteRule ^(.*) $ index.php?$1 [L,QSA]
I hope this helps someone!
Upvotes: 1
Reputation: 419
I figured what went wrong in my .env
SESSION_DOMAIN=.production.tld
removed that line and everything is now fine
Upvotes: 0
Reputation: 4202
Please use the Request
passed as an argument to the login()
method, and not the request which you have aliased at the top of the controller class.
public function login(Request $request)
{
$email = $request->input('email');
$password = $request->input('password');
echo $email;
}
Upvotes: 1
Reputation: 1175
Controller methods always receives a parameter Request
. Try this:
public function methodInYourController(Request $request)
{
$email = $request->get('email');
$password = $request->get('password');
}
Upvotes: 1