adamwathan/form

Call to member function class() on string

simplenotezy opened this issue · 11 comments

I get above error when I do:

Form::file('avatar')->class('file')

Shouldn't it be possible to do that?

Yeah that should definitely work, is there any more context you can paste?

This super minimal example seems to work as I'd expect:

<?php

require 'vendor/autoload.php';

use AdamWathan\Form\FormBuilder;

$builder = new FormBuilder;

echo $builder->file('avatar')->class('file');

I am not using the $builder variable, but simply Form::file('avatar')->class('file'). Maybe that is the issue?

Put together a tiny sample Laravel application and it seems to work: https://github.com/adamwathan/form-test/blob/master/resources/views/welcome.blade.php#L6

Any clues in there as to what you might be doing differently?

It sounds like @canfiax is attempting to use this library in a Laravel 4 project and did not override the default alias to resolve the correct FormBuilder class

In Laravel 4 the FormBuilder does not have fluent interface and all of it's input element methods return a string.

LaravelCollective's implementation has similar behavior except the respective methods return HtmlString objects, so the error would be slightly different.

@nCrazed I use Laravel 5.2

@nCrazed But the application was once Laravel 4 (I've upgraded). Maybe there could have been an issue in the upgrading process. If you pass me any instructions how to debug this I'd be happy to

What is the value of aliases.Form in your config/app.php file?

Here:

'Form'      => Illuminate\Html\FormFacade::class,
'BootForm' => AdamWathan\BootForms\Facades\BootForm::class,

I guess the issue is using Illuminate\Html\FormFacade instead of adamwathans form?

Good catch @nCrazed! Yeah @canfiax that looks like your issue. Update that alias reference and you should be good to go.

Thanks guys.

@adamwathan wonder if that will fix issue #58

everything works as expected. thanks