php - Laravel - Post request empty fields
230
I'm usingLaravel
withNginx
,PHP 7.1
andUbuntu 18
.
I have a login form as follows:
Login.blade.php:
{!! Form::open(['action' => '[email protected]'],['class' => 'form'])!!}
<h2 class="page_speed_1333068139">{{__("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 ofemail
andpassword
, they are always empty. Knowing that when I test onubuntu 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"
},
Answer
Solution:
Controller methods always receives a parameter
Request
. Try this:Answer
Solution:
Please use the
Request
passed as an argument to thelogin()
method, and not the request which you have aliased at the top of the controller class.Answer
Solution:
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:
I hope this helps someone!
Answer
Solution:
I figured what went wrong in my .env
removed that line and everything is now fine