someone can help me? thank you
Create a Form Macros in Laravel 5
Hi all, This is my first PHP Framework so i'm a noob about it, i'm sorry for that.
I decided to create my first Form Macros with this steps:
- I create a ServiceProvider
<?php
namespace App\Providers;
use Collective\Html\HtmlServiceProvider;
class MacroServiceProvider extends HtmlServiceProvider
{
/**
* Bootstrap the application services.
*
* @return void
*/
public function boot()
{
//
}
/**
* 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() . '/resources/macros/people.php';
}
}
- i create a new file people.php with inside the new FormMacro
<?php
/**
* This file has the People's Form Macros.
* It means: Teachers, Students and Contacts.
*/
Form::macro('active', function () {
$html =
'<select id="active" class="form-control" required>
<option value="" disabled selected>Attivo</option>
<option value="Si">Si</option>
<option value="No">No</option>
</select>';
return $html;
});
Now if i try to use my new 'active' Form Macro:
{{ Form::active() }}
i get this error:
Method active does not exist. (View: C:\xampp\htdocs\supsi-progetto\resources\views\backend\new-student.blade.php)
Honestly i don't know where is the mistake. I just follow a discussion inside of this forum and i'm pretty sure that i did all the steps correctly. Probably is missing something but i don't know what.
Thank you
Yes i did on my config/app.php i tried to trhow an exception and i got it. So it goes in there.
But honestrly the best way to reach this target is this one: https://laracasts.com/discuss/channels/tips/50-loading-form-macros
Please or to participate in this conversation.