Component problem

I have built a plugin that should function as a file manager where you can download on the frontend, the backend is almost ready and I am busy creating the component (which has started with scaffolding) I have already built several components but now I am running into a problem where I can’t figure out what I’m doing wrong. i get the following error:
The component 'Nielsvandendries\Toolkit\Components\Files' does not contain a method 'where'.
Below is the content of my component php file

<?php namespace Nielsvandendries\Toolkit\Components;

use Cms\Classes\ComponentBase;
use Nielsvandendries\Toolkit\Models\Filemanager;

/**
 * Files Component
 *
 * @link https://docs.octobercms.com/3.x/extend/cms-components.html
 */
class Files extends ComponentBase
{
    public $fileslist;
    
    public function componentDetails()
    {
        return [
            'name' => 'filesList',
            'description' => 'always watch the simpsons'
        ];
    }

    /**
     * @link https://docs.octobercms.com/3.x/element/inspector-types.html
     */
    public function defineProperties()
    {
        return [
            'file_owner' => [
                'title'             => 'File Owner',
                'description'       => 'Owner selectie',
                'type'              => 'dropdown',
            ]
        ];
    }

    public function getOwnerOptions()
    {
        return Files::get()->lists('file_owner', 'file_owner');
    }

    public function onRun()
    {
        $this->fileslist = Files::where('file_owner', $this->property('file_owner'))->get()->toArray();
    }
}

Can someone point me in the right direction here

The problem is that when this component runs, it executes the static method where, this does not exist. I think you’re trying to use the Files model, so you are missing a use statement. I would suggest renaming your Files component to something else, like FileBrowser, if you are using a Files model.

Hi,

The where statement can be executed on a Model but on a ComponentBase, I don’t think so ?

class Files extends ComponentBase
{}

I named the component “Files” because the model is called “Filemanager”. So changing the component to “FileBrowser” won’t change anything.

But the method “Where” is still set under the onRun

public function onRun()
    {
        $this->fileslist = Files::where('file_owner', $this->property('file_owner'))->get()->toArray();
    }

The strange thing is that I also have another OctoberCMS installation (v2) in which this works.
I also used that as a template.

you’re model that has ‘file_owner’ is Filemanager ?

if so, you have to query the right thing;

 $this->fileslist = Filemanager::where('file_owner', $this->property('file_owner'))->get()->toArray();

In that case the next error appears:
Class "Nielsvandendries\Toolkit\Models\Filemanager" not found

You have a typo in your use statement (and therefore, in your query)…

Your class seems to be named FileManager and not Filemanager.

image

use this code :

<?php namespace Nielsvandendries\Toolkit\Components;

use Cms\Classes\ComponentBase;
use Nielsvandendries\Toolkit\Models\FileManager;

/**
 * Files Component
 *
 * @link https://docs.octobercms.com/3.x/extend/cms-components.html
 */
class Files extends ComponentBase
{
    public $fileslist;
    
    public function componentDetails()
    {
        return [
            'name' => 'filesList',
            'description' => 'always watch the simpsons'
        ];
    }

    /**
     * @link https://docs.octobercms.com/3.x/element/inspector-types.html
     */
    public function defineProperties()
    {
        return [
            'file_owner' => [
                'title'             => 'File Owner',
                'description'       => 'Owner selectie',
                'type'              => 'dropdown',
            ]
        ];
    }

    public function getOwnerOptions()
    {
        return Files::get()->lists('file_owner', 'file_owner');
    }

    public function onRun()
    {
        $this->fileslist = FileManager::where('file_owner', $this->property('file_owner'))->get()->toArray();
    }
}

F#*K, right before you posted you reply i saw the type-o
:fearful: Sorry

I need a Beer badly

haha no worries, as long as it works :+1:

This absolutely works, next step is to display the uploaded files witdownload option in the component.
Busy weekend ahead.