Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Request instance in form helper singleton has different Illuminate\Http\Request object #192

Closed
StefanPrintezis opened this issue Dec 17, 2015 · 4 comments

Comments

@StefanPrintezis
Copy link
Contributor

public function testOrganizationsCreate() {
  $name = 'organisation name';
  $this->visit('/organizations/create')
          ->type($name, 'name')
          ->press('Save')
          ->seeInElement('div.organization-name h2', $name);
}

@get
.formhelper.requesthash:
string(32) "0000000033956ca30000000030ec80c9"
@post
Fformhelper.requesthash:
string(32) "0000000033956cf60000000030ec80c9"
request:
string(32) "0000000033956cc60000000030ec80c9" <-- action store request hash (Illuminate\Http\Request $request)
app.request:
string(32) "0000000033956cc60000000030ec80c9"<-- the apps request hash

When I call the following function the getRequest gets the Request instance from the formhelper but it has a different hash and the values are not found.
Note this only happens when running phpunit.

use Kris\LaravelFormBuilder\Form as BaseForm;

class Form extends BaseForm {

  public function getFieldValues() {
    $values = [];
    $request = $this->getRequest();
    foreach ($this->getFields() as $field => $type) {
      if ($request->exists($field)) {
        $values[$field] = $request->$field;
      }
    }
    return $values;
  }
}
@StefanPrintezis StefanPrintezis changed the title Request instance in form helper singleton has different Illuminate\Http\Request spl_object_hash Request instance in form helper singleton has different Illuminate\Http\Request Dec 17, 2015
@StefanPrintezis StefanPrintezis changed the title Request instance in form helper singleton has different Illuminate\Http\Request Request instance in form helper singleton has different Illuminate\Http\Request object Dec 17, 2015
@StefanPrintezis
Copy link
Contributor Author

My temporary fix is:
$form->setRequest(app('request'));
so it skips the formhelper->getrequest

@kristijanhusak
Copy link
Owner

We've already have that issue #149.
manually setting the request in controller before validation should do the work.
I'll try to fix it, to avoid problems like this. Thanks for reporting.

@kristijanhusak
Copy link
Owner

@StefanPrintezis I fixed it. Pull in dev-master and try it out.

@StefanPrintezis
Copy link
Contributor Author

It seems to be working correctly now. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants