how add model to form-builder?

Asked by At

I have model:

public function up()
    {
        Schema::create('tourist_objects', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name', 255);
            $table->text('description');
            $table->bigInteger('city_id')->unsigned();
            $table->foreign('city_id')->references('id')->on('cities')->onDelete('cascade');
            $table->bigInteger('user_id')->unsigned();
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
            $table->engine = "InnoDB";
        });
    }

I want use this component https://github.com/kristijanhusak/laravel-form-builder and create form. How can I create this form:

<form method="POST" action="http://mydomain.pl/forms">
    <input name="_token" type="hidden" value="xxxxxxxxxxxxxx">
    <div class="form-group">
        <label for="name" max-length="255" class="control-label">Name</label>
        <input type="text" class="form-control" id="name" value="Name from model">
    </div>
    <div class="form-group">
        <label for="lyrics" class="control-label">Description</label>
        <textarea name="lyrics" class="form-control">description value from data base</textarea>
    </div>
    <input type="submit" value="Save form">
</form>

?

Could I ask for an example with my data?

1 Answers

0
FMK On

You could use the command line to create a a form class:

php artisan make:form Forms/SongForm --fields="name:text, description:textarea, city_id:number, user_id:number"

If you want the city_id and user_id fields to be populated with data from the respecting models you could use the choice fields: http://kristijanhusak.github.io/laravel-form-builder/field/choice.html