You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Problem: Accessing $this->getModel() in Form class do not always return model provided
Affected Version: 1.15.0 (1.14.0 not affected)
Excepted Behavior: $this->getModel() always return Model provided
Actual Behavior: $this->getModel() sometimes returns input array, when $form->isValid() is called
This behavior seems introduced by 43346b2 and affecting version 1.15.0
How to reproduce:
Create a Controller that provide model to form builder
<?php
namespace App\Http\Controllers;
use App;
use App\Models\User;
use Kris\LaravelFormBuilder\FormBuilderTrait;
use Illuminate\Routing\Controller as BaseController;
class DebugController extends BaseController
{
use FormBuilderTrait;
public function handle() {
$form = $this->form(App\Forms\UserForm::class, [
'model' => User::whereId(1)->first()
]);
$form->isValid();
}
}
Create a Form that use $this->getModel()
<?php
namespace App\Forms;
use Kris\LaravelFormBuilder\Form;
class UserForm extends Form
{
public function buildForm()
{
$method = $this->getMethod();
$entity = $this->getModel();
$this->add('username', 'text', [
'label' => 'Username',
'rules' => ['required', 'max:255', in_array($method, ['get', 'post']) ? 'unique:users' : "unique:users,username,{$entity->id}"]
]);
}
}
Whoops!
ErrorException (E_NOTICE)
Trying to get property 'id' of non-object
Because $entity is not an object, $entity->id cause error
The text was updated successfully, but these errors were encountered:
Problem: Accessing
$this->getModel()
in Form class do not always return model providedAffected Version: 1.15.0 (1.14.0 not affected)
Excepted Behavior:
$this->getModel()
always return Model providedActual Behavior:
$this->getModel()
sometimes returns input array, when$form->isValid()
is calledThis behavior seems introduced by 43346b2 and affecting version 1.15.0
How to reproduce:
$this->getModel()
Because
$entity
is not an object,$entity->id
cause errorThe text was updated successfully, but these errors were encountered: