Git Product home page Git Product logo

Comments (4)

laraform avatar laraform commented on May 24, 2024

Hi Vincent,

Thank you, I appreciate a lot and I'm glad you like it!

Could you please help me by sending the exact code (with any dependencies it might rely on: migrations, models, etc.) which produces this error?

from laraform.

vincentvankekerix avatar vincentvankekerix commented on May 24, 2024

Thanks for the quick reply!
I just whipped up a test form for this specific error with just two fields, so I could single out the problem. The form has been created using the backend rendering method.

App\Forms\TestForm.php

<?php

namespace App\Forms;

use Laraform;

class TestForm extends Laraform
{
    public $endpoint = '/laraform/process';

    public $model = \App\TestForm::class;

    public $schema = [
        'name' => [
            'type' => 'text',
            'label' => 'Name',
            'rules' => 'required'
        ],
        'photo' => [
            'type' => 'image',
            'label' => 'Photo',
            'rules' => 'nullable'
        ]
    ];

    public $buttons = [
        0 => [
            'label' => 'Submit',
            'class' => 'btn-primary'
        ]
    ];
}

App\TestForm.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class TestForm extends Model
{
    protected $fillable = ['name', 'photo'];
}

The migration

    public function up()
    {
        Schema::create('test_forms', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->string('name');
            $table->string('photo')->nullable();
            $table->timestamps();
        });
    }

The frontend uses the default laraform component. Also files like filesystems.php are unchanged in this example. The error is still there, but like I wrote, the actual file is uploaded succesfully to the local disk. It just won't persist to the database.

Let me know if you'd need any more info!

from laraform.

laraform avatar laraform commented on May 24, 2024

Thank you for the detailed example! I've managed to look into it and realized that the documentation wasn't clear about that you must have an id element (or the equivalent primary key) when using files. This is because files are only processed after all the data is saved and they get updated, which makes possible custom store functions, etc.

So the only thing you need to do is to update your schema like:

App\Forms\TestForm.php

<?php

namespace App\Forms;

use Laraform;

class TestForm extends Laraform
{
    public $endpoint = '/laraform/process';

    public $model = \App\TestForm::class;

    public $schema = [
        'id' => [
            'type' => 'key',
        ],
        'name' => [
            'type' => 'text',
            'label' => 'Name',
            'rules' => 'required'
        ],
        'photo' => [
            'type' => 'image',
            'label' => 'Photo',
            'rules' => 'nullable'
        ]
    ];

    public $buttons = [
        0 => [
            'label' => 'Submit',
            'class' => 'btn-primary'
        ]
    ];
}

from laraform.

vincentvankekerix avatar vincentvankekerix commented on May 24, 2024

That does the trick, thanks a lot for your help!

from laraform.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.