Support the ongoing development of Laravel.io →
Security Forms Validation
Last updated 1 year ago.
0

Just another questio, How to populate my own macros automatically with Form::model? Best regards

Last updated 1 year ago.
0

Did you use

{{ Form::token() }}

??

Last updated 1 year ago.
0

Yes I used It, but the problem only occurs when I included my own Macros

Last updated 1 year ago.
0

Did you ever figure this one out?

Last updated 1 year ago.
0

Happen to have the same problem. Using Laravel 5 and having the form macros in my routes.php file, which I required. Routes are working, but the value of the csrf input field is empty. When I delete the form macros everything is working again.

Last updated 1 year ago.
0

This is how you fix it. Macros must be loaded after HTMLServiceProvider, that is why csrf tokens are not generating. After this, just add the service provider to your config/app.php. You can remove HTMLServiceProvider from the list since we are loading it here.


<?php namespace App\Providers;

use Illuminate\Html\HtmlServiceProvider;

class MacroServiceProvider extends HtmlServiceProvider
{
	/**
	 * Register the application services.
	 *
	 * @return void
	 */
	public function register()
	{
        // Macros must be loaded after the HTMLServiceProvider's
        // register method is called. Otherwise, csrf tokens
        // will not be generated
		parent::register();

        // Load macros
        require base_path() . '/path/to/your//macros.php';
	}
}

Last updated 1 year ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

sgsrra sgsrra Joined 15 Aug 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.