Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

video type needs two fields ? #213

Closed
MarcBrillault opened this issue Nov 1, 2016 · 9 comments
Closed

video type needs two fields ? #213

MarcBrillault opened this issue Nov 1, 2016 · 9 comments
Labels

Comments

@MarcBrillault
Copy link

I followed the steps mentioned here : https://laravel-backpack.readme.io/docs/crud-fields#video and had an issue :
SQLSTATE[42S22]: Column not found: 1054 Champ 'extract_link' inconnu dans field list

It seems I have to create two fields, xxx, and xxx_link in order for the video type to work.

Is it really necessary ? The video field already contains the link, as it is stored as json.

@OwenMelbz
Copy link
Contributor

@MarcBrillault if your column is called "extract" you only need to add 1 field.

Not sure why you're creating 2 fields, can you share your code?

@MarcBrillault
Copy link
Author

Here is my migration code:

// [...]
    public function up()
    {
        Schema::create('discs', function (Blueprint $table) {
            $table->increments('id');
            $table->string('title');
            $table->string('subtitle_fr')->nullable();
            $table->string('subtitle_en')->nullable();
            $table->string('publisher')->nullable();
            $table->text('text_fr')->nullable();
            $table->text('text_en')->nullable();
            $table->date('publication_date')->nullable();
            $table->string('image')->nullable();
            $table->string('extract')->nullable();

            // Sorting
            $table->integer('lft')->default(0);

            $table->timestamps();
        });
    }

And the code in DiscCrudController:

// [...]
        $this->crud->addField(
            [
                'name'  => 'extract',
                'label' => 'Extrait',
                'type'  => 'video',
            ]
        );
// [...]

When I do that, without adding the "extract_link" field in the migration, I have the above error.
The error disappears when I add the extract_link, and the extract field contains the full JSON, while the extract_link field only contains the full viedo url.

@OwenMelbz
Copy link
Contributor

The "extract" field needs to be TEXT as its more than likely longer than 255.

But I'm confirming now that all you need is

$this->crud->addField(
            [
                'name'  => 'extract',
                'label' => 'Extrait',
                'type'  => 'video',
            ]
        );

In your model, make sure its cast as an object.

Ignore the extract_link, field that is irrelevant and not needed to worry about, its purely a dummy field for the javascript.

Make sure you have no get/set mutators on the field. I've just tested on 2 different installs and its working as expected, so there must be a configuration issue your end thats conflicting.

Also make sure you don't have anything like "extract_link" in your $fillable, basically remove any of your code that even acknowledges the existence of _link, you do not need to worry about that.

Additionally try a composer update, just to make sure your on the latest, and make sure you have no customly published views overwriting the core one

@MarcBrillault
Copy link
Author

I still have the problem (And yes, I have made a composer update).

I'll try to test it on a fresh install this evening, I'll let you know.

@MarcBrillault
Copy link
Author

I made a fresh install (base, crud and generators).

I made the simplest possible migration:

    public function up()
    {
        Schema::create('discs', function (Blueprint $table) {
            $table->increments('id');
            $table->text('video')->nullable();
            $table->timestamps();
        });
    }

I generated all the files with php artisan backpack:crud disc

And I added this to Http/Controllers/Admin/DiscCrudController.php:


        $this->crud->addField(
            [
                'name'  => 'video',
                'label' => 'Vidéo',
                'type'  => 'video',
            ]
        );

And I still have the issue.

I uploaded my Laravel installation (minus the vendor dir) here : http://files.brillault.fr/dev/testBackpack.zip

@tabacitu
Copy link
Member

tabacitu commented Nov 3, 2016

Hi guys,

Found it! The zip helped, thank you. I think the problem is that there is a video_link input that reaches the create() and store() methods. If $fillable isn't specified, the CRUD will try to store all inputs. And it can't store video_link, because there is no such column.

@MarcBrillault , you can fix this by specifying in $fillable on the model what db columns are ok to be edited. It's good practice to use $fillable instead of $guarded because it's more restrictive. Otherwise a hacker could potentially insert a "created_at" or "updated_at" or other valid inputs that are more important in the front-end, click Save and overwrite the db entry.

@OwenMelbz , I think to prevent this problem ever happening again we could remove the video_link input from the "video" field type. Or just remove its name? I think that should work. What do you think?

Cheers!

@OwenMelbz
Copy link
Contributor

@tabacitu there is a PR here -> #214 which contains 2 fixes, one of them is the removal of the name attribute!

@MarcBrillault
Copy link
Author

Thanks to both of you ;)

@tabacitu
Copy link
Member

tabacitu commented Nov 6, 2016

Merged @OwenMelbz 's PR, so it's now fixed. Thanks guys. Cheers!

@tabacitu tabacitu closed this as completed Nov 6, 2016
@tabacitu tabacitu removed the ready label Nov 6, 2016
This was referenced Apr 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants