Home > Software design >  Unable to understand why I'm getting a substr error
Unable to understand why I'm getting a substr error

Time:11-16

I'm running laravel, and my page is giving me a substr error. Only problem is, I'm not running any string conversion commands or anything...

I've tried even removing all the code from the tpl file, and I get the error, but when I remove the render() function's loop and just set the $output (which is the info the blade template loops through) to $output=[]; then I don't get the error. ( PS: it's livewire)

Strange thing though, If I remove the loop that builds the $output completely, I don't get the error. But If I just manually set the $output = [] which yields the same result as removing the loop. I then get the substring error.

Honestly the pattern does not make sense nor does the error message log below... I'm completely lost and completely frustrated... Can anyone help me understand why I'm getting the substr message?

<!doctype html>
<html class="theme-light">
<!--
Facade\Ignition\Exceptions\ViewException: substr() expects parameter 1 to be string, object given (View: C:\xampp\htdocs\mws\resources\views\user\filemanager\index.blade.php) in file C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Support\Str.php on line 222

#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions-&gt;handleError(2, 'substr() expect...', 'C:\\xampp\\htdocs...', 222, Array)
#1 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Support\Str.php(222): substr(Object(Illuminate\Filesystem\FilesystemAdapter), -6)
#2 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Database\DatabaseManager.php(103): Illuminate\Support\Str::endsWith(Object(Illuminate\Filesystem\FilesystemAdapter), Array)
#3 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Database\DatabaseManager.php(77): Illuminate\Database\DatabaseManager-&gt;parseConnectionName(Object(Illuminate\Filesystem\FilesystemAdapter))
#4 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php(1653): Illuminate\Database\DatabaseManager-&gt;connection(Object(Illuminate\Filesystem\FilesystemAdapter))
#5 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php(1619): Illuminate\Database\Eloquent\Model::resolveConnection(Object(Illuminate\Filesystem\FilesystemAdapter))
#6 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Concerns\HasAttributes.php(1212): Illuminate\Database\Eloquent\Model-&gt;getConnection()
#7 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Concerns\HasAttributes.php(1124): Illuminate\Database\Eloquent\Model-&gt;getDateFormat()
#8 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Concerns\HasAttributes.php(189): Illuminate\Database\Eloquent\Model-&gt;asDateTime('2021-11-14 22:5...')
#9 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Concerns\HasAttributes.php(151): Illuminate\Database\Eloquent\Model-&gt;addDateAttributesToArray(Array)
#10 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php(1485): Illuminate\Database\Eloquent\Model-&gt;attributesToArray()
#11 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Concerns\HasAttributes.php(319): Illuminate\Database\Eloquent\Model-&gt;toArray()
#12 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php(1485): Illuminate\Database\Eloquent\Model-&gt;relationsToArray()
#13 C:\xampp\htdocs\mws\vendor\livewire\livewire\src\HydrationMiddleware\HydratePublicProperties.php(229): Illuminate\Database\Eloquent\Model-&gt;toArray()
#14 C:\xampp\htdocs\mws\vendor\livewire\livewire\src\HydrationMiddleware\HydratePublicProperties.php(209): Livewire\HydrationMiddleware\HydratePublicProperties::filterData(Object(App\Http\Livewire\Filemanager), 'selectedUser')
#15 C:\xampp\htdocs\mws\vendor\livewire\livewire\src\HydrationMiddleware\HydratePublicProperties.php(102): Livewire\HydrationMiddleware\HydratePublicProperties::dehydrateModel(Object(App\Models\User), 'selectedUser', Object(Livewire\Response), Object(App\Http\Livewire\Filemanager))
#16 [internal function]: Livewire\HydrationMiddleware\HydratePublicProperties::Livewire\HydrationMiddleware\{closure}(Object(App\Models\User), 'selectedUser')
#17 C:\xampp\htdocs\mws\vendor\livewire\livewire\src\HydrationMiddleware\HydratePublicProperties.php(130): array_walk(Array, Object(Closure))
#18 C:\xampp\htdocs\mws\vendor\livewire\livewire\src\LifecycleManager.php(141): Livewire\HydrationMiddleware\HydratePublicProperties::dehydrate(Object(App\Http\Livewire\Filemanager), Object(Livewire\Response))
#19 C:\xampp\htdocs\mws\vendor\livewire\livewire\src\LivewireManager.php(106): Livewire\LifecycleManager-&gt;initialDehydrate()
#20 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Support\Facades\Facade.php(261): Livewire\LivewireManager-&gt;mount('filemanager')
#21 C:\xampp\htdocs\mws\resources\views/user/filemanager/index.blade.php(10): Illuminate\Support\Facades\Facade::__callStatic('mount', Array)
#22 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Filesystem\Filesystem.php(107): require('C:\\xampp\\htdocs...')
#23 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Filesystem\Filesystem.php(108): Illuminate\Filesystem\Filesystem::Illuminate\Filesystem\{closure}()
#24 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\View\Engines\PhpEngine.php(58): Illuminate\Filesystem\Filesystem-&gt;getRequire('C:\\xampp\\htdocs...', Array)
#25 C:\xampp\htdocs\mws\vendor\livewire\livewire\src\ComponentConcerns\RendersLivewireComponents.php(35): Illuminate\View\Engines\PhpEngine-&gt;evaluatePath('C:\\xampp\\htdocs...', Array)
#26 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\View\Engines\CompilerEngine.php(61): Livewire\CompilerEngineForIgnition-&gt;evaluatePath('C:\\xampp\\htdocs...', Array)
#27 C:\xampp\htdocs\mws\vendor\facade\ignition\src\Views\Engines\CompilerEngine.php(37): Illuminate\View\Engines\CompilerEngine-&gt;get('C:\\xampp\\htdocs...', Array)
#28 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\View\View.php(139): Facade\Ignition\Views\Engines\CompilerEngine-&gt;get('C:\\xampp\\htdocs...', Array)
#29 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\View\View.php(122): Illuminate\View\View-&gt;getContents()
#30 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\View\View.php(91): Illuminate\View\View-&gt;renderContents()
#31 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Http\Response.php(69): Illuminate\View\View-&gt;render()
#32 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Http\Response.php(35): Illuminate\Http\Response-&gt;setContent(Object(Illuminate\View\View))
#33 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Routing\Router.php(794): Illuminate\Http\Response-&gt;__construct(Object(Illuminate\View\View), 200, Array)
#34 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Routing\Router.php(763): Illuminate\Routing\Router::toResponse(Object(Illuminate\Http\Request), Object(Illuminate\View\View))
#35 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Routing\Router.php(695): Illuminate\Routing\Router-&gt;prepareResponse(Object(Illuminate\Http\Request), Object(Illuminate\View\View))
#36 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(128): Illuminate\Routing\Router-&gt;Illuminate\Routing\{closure}(Object(Illuminate\Http\Request))
#37 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Routing\Middleware\SubstituteBindings.php(50): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#38 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Routing\Middleware\SubstituteBindings-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
#39 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Auth\Middleware\Authenticate.php(44): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#40 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Auth\Middleware\Authenticate-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
#41 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\VerifyCsrfToken.php(78): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#42 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
#43 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\View\Middleware\ShareErrorsFromSession.php(49): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#44 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\View\Middleware\ShareErrorsFromSession-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
#45 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Session\Middleware\AuthenticateSession.php(58): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#46 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Session\Middleware\AuthenticateSession-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
#47 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Session\Middleware\StartSession.php(121): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#48 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Session\Middleware\StartSession.php(64): Illuminate\Session\Middleware\StartSession-&gt;handleStatefulRequest(Object(Illuminate\Http\Request), Object(Illuminate\Session\Store), Object(Closure))
#49 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Session\Middleware\StartSession-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
#50 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#51 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
#52 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Cookie\Middleware\EncryptCookies.php(67): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#53 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Cookie\Middleware\EncryptCookies-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
#54 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(103): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#55 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Routing\Router.php(697): Illuminate\Pipeline\Pipeline-&gt;then(Object(Closure))
#56 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Routing\Router.php(672): Illuminate\Routing\Router-&gt;runRouteWithinStack(Object(Illuminate\Routing\Route), Object(Illuminate\Http\Request))
#57 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Routing\Router.php(636): Illuminate\Routing\Router-&gt;runRoute(Object(Illuminate\Http\Request), Object(Illuminate\Routing\Route))
#58 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Routing\Router.php(625): Illuminate\Routing\Router-&gt;dispatchToRoute(Object(Illuminate\Http\Request))
#59 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(167): Illuminate\Routing\Router-&gt;dispatch(Object(Illuminate\Http\Request))
#60 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(128): Illuminate\Foundation\Http\Kernel-&gt;Illuminate\Foundation\Http\{closure}(Object(Illuminate\Http\Request))
#61 C:\xampp\htdocs\mws\vendor\livewire\livewire\src\DisableBrowserCache.php(19): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#62 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Livewire\DisableBrowserCache-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
#63 C:\xampp\htdocs\mws\vendor\barryvdh\laravel-debugbar\src\Middleware\InjectDebugbar.php(60): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#64 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Barryvdh\Debugbar\Middleware\InjectDebugbar-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
#65 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php(21): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#66 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull.php(31): Illuminate\Foundation\Http\Middleware\TransformsRequest-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
#67 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
#68 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TransformsRequest.php(21): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#69 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\TrimStrings.php(40): Illuminate\Foundation\Http\Middleware\TransformsRequest-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
#70 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Foundation\Http\Middleware\TrimStrings-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
#71 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\ValidatePostSize.php(27): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#72 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Foundation\Http\Middleware\ValidatePostSize-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
#73 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance.php(86): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#74 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
#75 C:\xampp\htdocs\mws\vendor\fruitcake\laravel-cors\src\HandleCors.php(38): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#76 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Fruitcake\Cors\HandleCors-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
#77 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Http\Middleware\TrustProxies.php(39): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#78 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(167): Illuminate\Http\Middleware\TrustProxies-&gt;handle(Object(Illuminate\Http\Request), Object(Closure))
#79 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Pipeline\Pipeline.php(103): Illuminate\Pipeline\Pipeline-&gt;Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#80 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(142): Illuminate\Pipeline\Pipeline-&gt;then(Object(Closure))
#81 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Foundation\Http\Kernel.php(111): Illuminate\Foundation\Http\Kernel-&gt;sendRequestThroughRouter(Object(Illuminate\Http\Request))
#82 C:\xampp\htdocs\mws\public\index.php(52): Illuminate\Foundation\Http\Kernel-&gt;handle(Object(Illuminate\Http\Request))
#83 {main}

Important Side Note The odd thing is. This loop connects via FTP to collect folders. If I change the FTP user credentials to another user's credentials, I don't get the error. So it's something in this user's directories (it would seem), but boh user's directories only have 1 folder, same folder name too. So everything matches from what I can see perfectly between the two.

I can also login with FileZilla to both. So it's not a server issue I think...

Second Site Note I checked on the FTP server logs and noticed something different's happening.

If logged into the 1 user (that does not give the error), I am just seeing logged in confirmation then logout... But with my user that's giving the issue I am noticing something different happening:

Nov 15 01:56:51 node1 pure-ftpd[7777]: (?@10.0.0.13) [INFO] test is now logged in
Nov 15 01:56:51 node1 pure-ftpd[7777]: (test@10.0.0.13) [INFO] Can't change directory to test.php: Not a directory
Nov 15 01:56:51 node1 pure-ftpd[7777]: ([email protected]) [INFO] Logout.

The part that's even odder is that the directory I am asking laravel to query is the / directory which only has the domains folder. The test.php is in the domains directory so it's not even being queried at the moment though?

filemanager.index.blade

<x-narrow-layout>    
    <x-slot name="content">
        @livewire('filemanager')
    </x-slot>
</x-narrow-layout>

filemanager Controller

namespace App\Http\Livewire;

use Livewire\Component;
use Illuminate\Support\Facades\Auth;
use App\Models\User;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\Hash;
use App\Http\Livewire\DataTable\WithPerPagePagination;
use App\Http\Livewire\DataTable\WithSorting;
use App\Http\Livewire\DataTable\WithCachedRows;

class Filemanager extends Component
{
    use WithSorting, WithCachedRows;
    
    public $showEditModal = false;
    public $showDeleteModal = false;
    public $selectedUserId = '';
    public $selectedUser = NULL;
    public $openDirectory = '';
    public $editing;
    public $editingFile;
    public $selected = [];
    public $selectPage = false;
    public $selectAll = false;
    
    public $filters = [
        'search' => ''
    ];
    
    protected $queryString = ['selectedUserId', 'openDirectory'];

    public function rules() {
        $rules = [
            'editing' => 'nullable'
        ];

        return $rules;
    }
    
    public function selectUserFtp($user_id){
        $this->selectedUserId = $user_id == $this->selectedUserId ? '' : $user_id;
        $this->openDirectory = '';
    }
    
    public function updateActivePath($path){
        $this->openDirectory = $path;
    }
    
    public function editFile($file){
        $this->editing = $this->selectedUser->MainFTPUser->GetFileContent($file);
        $this->editingFile = $file;   
        $this->showEditModal = true;
    }

    public function saveFile() {
        $this->validate();
        $this->selectedUser->MainFTPUser->SaveFileContent($this->editingFile, $this->editing);
        
        $this->showEditModal = false;
        
        $this->editing = '';
        $this->editingFile ='';
    }

    public function duplicateFile($file) {
        $this->editing = $this->selectedUser->MainFTPUser->GetFileContent($file);
        $this->editingFile = $file;
        
        $this->selectedUser->MainFTPUser->SaveFileContent($this->editingFile.'_copy', $this->editing);
        
        $this->editing = '';
        $this->editingFile ='';
    }

    public function deleteFile($file) {
        $this->selectedUser->MainFTPUser->deleteFile($file);
    }
    
    public function updatedSelectPage($value) {
        
            $this->selected = $value 
                    ? $this->Rows->pluck('id')->map(fn($id) => (string) $id)
                    : $this->selected = [];
    }
    
    public function render()
    {
        $sub_accounts_array = User::query()
                                ->where(function ($query) {
                                    $query->wherein('id', Auth::user()->SubUsersIDS)
                                    ->orWhere('id', Auth::user()->id);
                                })
                                ->orderBy('username')
                                ->get();
        
        $this->selectedUser = $this->selectedUserId!='' ? User::find($this->selectedUserId) : NULL;
                              
        $directoryContent = [];
        $directoryDirectories = [];
        $output = [];
        
        if($this->selectedUser!=NULL){
            $directoryDirectories = $this->selectedUser->MainFTPUser->DirectoryFolders($this->openDirectory);
            $directoryContent = $this->selectedUser->MainFTPUser->DirectoryFiles($this->openDirectory);
        }
        
        $output = [];
        foreach($directoryDirectories as $folder){
            $output[] = [
                'id' =>   md5($folder['path']),
                'path' =>   $folder['path'],
                'label' =>   $folder['label'],
                'size' =>   '1 kb',
                'permissions' =>   '0000',
                'date' =>   $this->selectedUser->MainFTPUser->getDateModified($folder['path']),
                'type' =>   'folder',
            ];
        }
        foreach($directoryContent as $file){
            $output[] = [
                'id' =>   md5($file['path']),
                'path' =>   $file['path'],
                'label' =>   $file['label'],
                'size' =>   $this->selectedUser->MainFTPUser->getFileSize($file['path']),
                'permissions' =>   '0000',
                'date' =>   $this->selectedUser->MainFTPUser->getDateModified($file['path']),
                'type' =>   'file',
            ];
        }

        return view('livewire.filemanager')
                ->with('sub_accounts', $sub_accounts_array)
                ->with('directoryFilesAndFolders', $output);
    }
}

CodePudding user response:

From the error stack:

#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(2, 'substr() expect...', 'C:\xampp\htdocs...', 222, Array)

#1 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Support\Str.php(222): substr(Object(Illuminate\Filesystem\FilesystemAdapter), -6)

#2 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Database\DatabaseManager.php(103): Illuminate\Support\Str::endsWith(Object(Illuminate\Filesystem\FilesystemAdapter), Array)

#3 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Database\DatabaseManager.php(77): Illuminate\Database\DatabaseManager->parseConnectionName(Object(Illuminate\Filesystem\FilesystemAdapter))

#4 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php(1653): Illuminate\Database\DatabaseManager->connection(Object(Illuminate\Filesystem\FilesystemAdapter))

#5 C:\xampp\htdocs\mws\vendor\laravel\framework\src\Illuminate\Database\Eloquent\Model.php(1619): Illuminate\Database\Eloquent\Model::resolveConnection(Object(Illuminate\Filesystem\FilesystemAdapter))

...

The Illuminate\Support\Str::endsWith method is called on a Illuminate\Filesystem\FilesystemAdapter object instead of string.

FilesystemAdapter was first used in #5 of the stack (Illuminate\Database\Eloquent\Model::resolveConnection) then propagated through. There was a few Eloquent internal calls from that below. From lower level (#13 - #19), you can see a few livewire calls.

My guess is that your combined use of livewire with your Filemanager class might cause issue that results in using FilesystemAdapter, incorrectly, as the database connection string.

CodePudding user response:

Ok Guys, I was able to narrow it down. Based on @koala's answer hinting that it was in the model, I had 2 functions:

$directoryDirectories = $this->selectedUser->MainFTPUser->DirectoryFolders($this->openDirectory);
$directoryContent = $this->selectedUser->MainFTPUser->DirectoryFiles($this->openDirectory);

Which if I commented them out, everything worked perfectly well. Why I don't understand, because on any other user it was working perfectly...

but I moved all the "Functions" I had in the model, stuff like adding and removing FTP users, out of the model, leaving only the attributes and the relationships in there, and I moved the rest all to the livewire controller.

After doing this, It fixed my issue, I no longer had a substr issue.

I still don't understand why it was so unpredictable behavior, But thanks for the tips. That lead me to finding the issue.

  • Related