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_1045885605">{{__("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"
    },
472

Answer

Solution:

Controller methods always receives a parameterRequest. Try this:

public function methodInYourController(Request $request)
{
    $email = $request->get('email');
    $password = $request->get('password');
}
480

Answer

Solution:

Please use theRequest passed as an argument to thelogin() 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;
  }
133

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:

# Handle Front Controller ...
     RewriteCond %{REQUEST_FILENAME} !-D
     RewriteCond %{REQUEST_FILENAME} !-F
     RewriteRule ^(.*) $ index.php?$1 [L,QSA]

I hope this helps someone!

149

Answer

Solution:

I figured what went wrong in my .env

SESSION_DOMAIN=.production.tld

removed that line and everything is now fine

People are also looking for solutions to the problem: php - Laravel - Update $guarded array based on different config

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.