Honeypot icon indicating copy to clipboard operation
Honeypot copied to clipboard

Does not recognize honeypot method

Open enchance opened this issue 10 years ago • 36 comments

Might just be me but I'm getting: An exception has been thrown during the rendering of a template ("Method honeypot does not exist.") in my view. I'm using Twig and access your method as such, form_honeypot('hname', 'htime').

I also have my own custom macros which I'm able to access as form_mymacroname('xxx') so I don't think it's the macro but I might be wrong on this.

enchance avatar Apr 08 '14 01:04 enchance

Hi,

Does Laravel find the service provider as expected ? Can you call its methods ?

lud avatar Apr 29 '14 13:04 lud

It's really not working. I tried using <?php echo Form::honeypot('h', 't'); ?> on a non-twig view and I still got Method honeypot does not exist.. Everything is installed exactly as instructed.

enchance avatar Apr 30 '14 16:04 enchance

Are you sure you have the service provider added in the app.php? 'Msurguy\Honeypot\HoneypotServiceProvider',

msurguy avatar Apr 30 '14 16:04 msurguy

Yes. Btw, I'm using L4.1. Perhaps this version is affecting your package?

enchance avatar Apr 30 '14 16:04 enchance

I'm using L4.1 and it's ok.

I believe you must add the service provider at the end of the providers array, not at the top. It that all right ?

lud avatar May 01 '14 12:05 lud

No, it didn't. Let me check this might be an isolated incident having to do with some of the core classes I've extended.

enchance avatar May 04 '14 14:05 enchance

Does my recent changes to the service provider fix this issue?

garygreen avatar Mar 13 '15 23:03 garygreen

I have the exact same problem. I'm using Laravel 4.2 and I've added 'Msurguy\Honeypot\HoneypotServiceProvider' to app.php

rombat avatar Mar 20 '15 10:03 rombat

@rombat are you using twig too? Do you use twigbridge or anything like that?

garygreen avatar Mar 20 '15 10:03 garygreen

Nope I'm using Blade. I've just added {{ Form::honeypot('my_name', 'my_time') }} in a form to test Honeypot.

rombat avatar Mar 20 '15 10:03 rombat

Here's the Exception:


Open: /home/vagrant/Code/laravel/vendor/laravel/framework/src/Illuminate/Support/Traits/MacroableTrait.php

        public static function __callStatic($method, $parameters)
        {
            if (static::hasMacro($method))
            {
                return call_user_func_array(static::$macros[$method], $parameters);
            }

            throw new \BadMethodCallException("Method {$method} does not exist.");
        }


Exception message: Method honeypot does not exist.

rombat avatar Mar 20 '15 10:03 rombat

Can you paste your app.php providers array too please.

garygreen avatar Mar 20 '15 10:03 garygreen

    'providers' => array(

        'Illuminate\Foundation\Providers\ArtisanServiceProvider',
        'Illuminate\Auth\AuthServiceProvider',
        'Illuminate\Cache\CacheServiceProvider',
        'Illuminate\Session\CommandsServiceProvider',
        'Illuminate\Foundation\Providers\ConsoleSupportServiceProvider',
        'Illuminate\Routing\ControllerServiceProvider',
        'Illuminate\Cookie\CookieServiceProvider',
        'Illuminate\Database\DatabaseServiceProvider',
        'Illuminate\Encryption\EncryptionServiceProvider',
        'Illuminate\Filesystem\FilesystemServiceProvider',
        'Illuminate\Hashing\HashServiceProvider',
        'Illuminate\Html\HtmlServiceProvider',
        'Illuminate\Log\LogServiceProvider',
        'Illuminate\Mail\MailServiceProvider',
        'Illuminate\Database\MigrationServiceProvider',
        'Illuminate\Pagination\PaginationServiceProvider',
        'Illuminate\Queue\QueueServiceProvider',
        'Illuminate\Redis\RedisServiceProvider',
        'Illuminate\Remote\RemoteServiceProvider',
        'Illuminate\Auth\Reminders\ReminderServiceProvider',
        'Illuminate\Database\SeedServiceProvider',
        'Illuminate\Session\SessionServiceProvider',
        'Illuminate\Translation\TranslationServiceProvider',
        'Illuminate\Validation\ValidationServiceProvider',
        'Illuminate\View\ViewServiceProvider',
        'Illuminate\Workbench\WorkbenchServiceProvider',
        'Barryvdh\Debugbar\ServiceProvider',
        'Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider',
        'Roumen\Asset\AssetServiceProvider',
        'Way\Generators\GeneratorsServiceProvider',
        'DaveJamesMiller\Breadcrumbs\ServiceProvider',
        'Jenssegers\Agent\AgentServiceProvider',
        'Arg\Tagcloud\TagcloudServiceProvider',
        'Former\FormerServiceProvider',
        'Bootstrapper\BootstrapperServiceProvider',
        'Lib\Search\SearchServiceProvider',
        'Lib\Validation\ValidationExtensionServiceProvider',
        'Kmd\Logviewer\LogviewerServiceProvider',
        'Indatus\Dispatcher\ServiceProvider',
        'BigName\BackupManager\Integrations\Laravel\BackupManagerServiceProvider',
        'Spatie\Glide\GlideServiceProvider',
        'Msurguy\Honeypot\HoneypotServiceProvider',
    ),

rombat avatar Mar 20 '15 10:03 rombat

if possible, can you comment out/remove these providers and see if it honeypot works?

    'Former\FormerServiceProvider',
    'Bootstrapper\BootstrapperServiceProvider',

garygreen avatar Mar 20 '15 10:03 garygreen

Also are you using the latest dev-master of honeypot? Latest tagged version of honeypot is quite old

garygreen avatar Mar 20 '15 11:03 garygreen

Yep, I have "vinicius73/seotools": "dev-master". It was due to Former actually. My form was opened/closed with Former. I tried {{ Former::honeypot('my_name', 'my_time') }} and it works. Well, actually, sort of: only the 'my name' field is added, 'my time' is not.

Is there a way to make it work? I'm using Former and Bootstrapper\Form in almost all my forms.

rombat avatar Mar 20 '15 11:03 rombat

Weird how the my time field is not added, what's the actual raw HTML output for the honeypot section? You got quite a lot of dependencies to be honest, could be anything.

I did take a look at former and bootstrapper service provider on github as I originally suspected it was replacing Laravel's built in form and therefore overriding the macros, but that doesn't seem like the case. Can you setup a real bare repository on github that replicates the issue in the min number of steps I can take a look.

garygreen avatar Mar 20 '15 12:03 garygreen

Ever since this commit: f18c81f814ca7a4f0d82dc76b78d2790b277c0f5

My regular 4.2 application fails with honeypot method does not exist. I reverted back to the commit prior to that one and everything worked.

iBotPeaches avatar Mar 23 '15 15:03 iBotPeaches

@iBotPeaches what's in your app.providers array?

garygreen avatar Mar 23 '15 15:03 garygreen

    'providers' => array(
        'Illuminate\Foundation\Providers\ArtisanServiceProvider',
        'Illuminate\Auth\AuthServiceProvider',
        'Illuminate\Cache\CacheServiceProvider',
        'Illuminate\Session\CommandsServiceProvider',
        'Illuminate\Foundation\Providers\ConsoleSupportServiceProvider',
        'Illuminate\Routing\ControllerServiceProvider',
        'Illuminate\Cookie\CookieServiceProvider',
        'Illuminate\Database\DatabaseServiceProvider',
        'Illuminate\Encryption\EncryptionServiceProvider',
        'Illuminate\Filesystem\FilesystemServiceProvider',
        'Illuminate\Hashing\HashServiceProvider',
        'Illuminate\Html\HtmlServiceProvider',
        'Illuminate\Log\LogServiceProvider',
        'Illuminate\Database\MigrationServiceProvider',
        'Illuminate\Pagination\PaginationServiceProvider',
        'Illuminate\Queue\QueueServiceProvider',
        'Illuminate\Redis\RedisServiceProvider',
        'Illuminate\Remote\RemoteServiceProvider',
        'Illuminate\Database\SeedServiceProvider',
        'Illuminate\Session\SessionServiceProvider',
        'Illuminate\Translation\TranslationServiceProvider',
        'Illuminate\Validation\ValidationServiceProvider',
        'Illuminate\View\ViewServiceProvider',
        'Illuminate\Workbench\WorkbenchServiceProvider',
        'GrahamCampbell\Markdown\MarkdownServiceProvider',
        'App\Form\Providers\FormBuilderServiceProvider',
        'App\Auth\Providers\PasswordBrokerServiceProvider',
        'Intervention\Image\ImageServiceProvider',
        'Zizaco\Entrust\EntrustServiceProvider',
        'Msurguy\Honeypot\HoneypotServiceProvider',
        'Laravel\Cashier\CashierServiceProvider',
        'Appitventures\Phpgmaps\PhpgmapsServiceProvider',
        'Snowfire\Mail\MailServiceProvider',
        'Bugsnag\BugsnagLaravel\BugsnagLaravelServiceProvider',

iBotPeaches avatar Mar 23 '15 15:03 iBotPeaches

Can you comment out App\Form\Providers\FormBuilderServiceProvider and try if honeypot works?

garygreen avatar Mar 23 '15 15:03 garygreen

Yes that fixed it, but then removed all my custom Form functions that I had created, so can't really use that fix.

iBotPeaches avatar Mar 23 '15 15:03 iBotPeaches

Of course not, just trying to find the cause. Can you post your FormBuilderServiceProvider?

garygreen avatar Mar 23 '15 15:03 garygreen

FormBuilderServiceProvider.php

<?php namespace App\Form\Providers;

use Illuminate\Support\ServiceProvider as IlluminateServiceProvider;
use App\Form\FormBuilder as FormBuilder;

class FormBuilderServiceProvider extends IlluminateServiceProvider {

    /**
     * Indicates if loading of the provider is deferred.
     *
     * @var bool
     */
    protected $defer = true;

    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        $this->app->bindShared('formbuilder', function($app)
        {
            $form = new FormBuilder($app['html'], $app['url'], $app['session.store']->getToken());

            return $form->setSessionStore($app['session.store']);
        });
    }

    /**
     * Get the services provided by the provider.
     *
     * @return array
     */
    public function provides()
    {
        return array('formbuilder');
    }
}

iBotPeaches avatar Mar 23 '15 15:03 iBotPeaches

Does your FormBuilder extends Laravels one? How are you using your custom form builder, do you have a facade?

garygreen avatar Mar 23 '15 15:03 garygreen

Yep my custom FormBuilder extends laravel.

use \Illuminate\Html\FormBuilder as IlluminateFormBuilder;

class FormBuilder extends IlluminateFormBuilder {

Which then changes the Facade in app/config to point to my custom one, allowing me to use my custom functions in addition to the laravel ones.

        'Form'            => 'App\Form\FormBuilderFacade',

iBotPeaches avatar Mar 23 '15 15:03 iBotPeaches

The new service provider in honeypot will listen for when the form alias get's resolved from the container, then register all the macros. The default alias in Laravel is form but I notice you've changed it to formbuilder in your provider. Can you try changing it to just form which will override Laravel's built in one.

garygreen avatar Mar 23 '15 15:03 garygreen

That worked. Thank you!

No idea why I used formbuilder vs form.

iBotPeaches avatar Mar 23 '15 16:03 iBotPeaches

@garygreen : here's a test repository with the error: https://github.com/rombat/test-laravel-honeypot It's just a fresh install of Laravel 4.2 with the packages I use on my project, and the default "hello" view edited with honeypot method.

rombat avatar Mar 23 '15 18:03 rombat

I've created a PR which will help resolve #25

garygreen avatar Mar 23 '15 20:03 garygreen