Closed endeloper closed 2 years ago
I thought this was resolved with the 0.0.21 update. Can you check and make sure you have the latest version installed?
I have version 0.0.21 installed.
Which version of Laravel are you using?
It's 8.46.0
I was testing this with Laravel 8.83.5 and version 0.0.21 and am not able to reproduce this issue.
I also install 8.46.0 to test your specific version and I'm still not able to reproduce this after running through our tests. What is the function you're calling which is triggering this, or can you post a block of your code where you're hitting this error?
This was an issue with Laravel 9 before it was supported, but I haven't seen it in 8, so I'm not sure what is happening here.
I report the interesting part of the stack trace:
FilemakerController.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\FM_Unit;
class FilemakerController extends Controller
{
public function prova(String $database) {
$unitaPresaDaFilemaker = FM_Unit::first();
dd($unitaPresaDaFilemaker);
}
}
... calls FM_Unit, which is defined here:
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use BlueFeather\EloquentFileMaker\Database\Eloquent\FMModel;
class FM_Unit extends FMModel
{
use HasFactory;
protected $layout = "Lista completa US";
protected $fieldMapping = [
'anteriore a' => 'anteriore_a',
.....
];
}
At runtime, when FMModel is instantiated, the extended class Model's __callStatic()
function is called:
public static function __callStatic($method, $parameters) { return (new static)->$method(...$parameters);}
... then the same class's __call()
function:
return $this->forwardCallTo($this->newQuery(), $method, $parameters);
... which needs the result of newQuery()
:
return $this->registerGlobalScopes($this->newQueryWithoutScopes());
... to have in two passages a new query builder without global scopes nor eager loading through two subsequents calls to newQueryWithoutScopes()
and newModelQuery()
.
In this last function, this code is executed:
return $this->newEloquentBuilder($this->newBaseQueryBuilder())->setModel($this);
...which tries to call FMModel's newEloquentBuilder($query)
function, passing in the result of $this->newBaseQueryBuilder() as $query parameter.
This is where all stops, exposing that the $query parameter should have been a FMBaseBuilder type and not a Bulder type.
Ah! I suspect your connection may not be set to use your FileMaker database and may instead be trying to query a SQL database. Be sure you have set up a FileMaker connection either as your default connection or set your model to use your configured FileMaker connection.
in config/database.php
'filemaker' => [
'driver' => 'filemaker',
'host' => env('DB_HOST', 'fms.mycompany.com'),
'database' => env('DB_DATABASE', 'MyFileName'),
'username' => env('DB_USERNAME', 'myusername'),
'password' => env('DB_PASSWORD', ''),
'prefix' => env('DB_PREFIX', ''),
'version' => env('DB_VERSION', 'vLatest'),
'protocol' => env('DB_PROTOCOL', 'https'),
]
Unfortunately this is not the case...
In my .env
file I added:
FM_CONNECTION=filemaker
FM_HOST=147.162.42.28
FM_PORT=443
FM_DATABASE="ADaM Cossar 1_9_5"
FM_USERNAME=xxxxx.xxxxxx
FM_PASSWORD=xxxxxx
FM_PREFIX=""
FM_VERSION="vLatest"
FM_PROTOCOL="https"
and in config/database.php
:
'filemaker' => [
'driver' => 'filemaker',
//'url' => env('DATABASE_URL'),
'host' => env('FM_HOST'),
'port' => env('FM_PORT'),
'database' => env('FM_DATABASE'),
'username' => env('FM_USERNAME'),
'password' => env('FM_PASSWORD'),
'prefix' => env('FM_PREFIX', ''),
'version' => env('FM_VERSION', 'vLatest'),
'protocol' => env('FM_PROTOCOL', 'https')
],
I think you have FM_CONNECTION
instead of DB_CONNECTION
to set your apps default database connection.
Also, probably the next issue you're going to run into is that if you're using FM_HOST with an IP address and HTTPS you are not going to be able to get a secure HTTPS connection. An SSL certificate will require a domain name to validate the certificate. You'll need to set that up with a real domain name.
No activity - closing issue.
Hey, commenting here because I have a very similar issue, however in my case it seems to only happen when creating a record. Something like Order::create($attributes);
Also, this only happened after upgrading from version 0.0.21
to 0.0.23
. I also tried updating to 0.0.27
, but that didn't help. My Laravel version is 9.11.0
in case thats relevant.
In contrast to the previous poster I do not have the filemaker connection set up as the default connection. Instead i set the $connection
property on the model.
To maybe give you a starting point, I noticed, that in the 0.0.23
release the __construct
method was removed from the FileMakerConnection
class and in there you would call $this->setConnection($connectionName, $config);
, which I think is missing entirely now.
Can you post an example repo where you have this error? I haven't been able to reproduce this.
Alright, I set up a fresh install of Laravel and made the necessary changes. You can view the latest commit to see the actual code I implemented.
Here's the repo: https://github.com/lgebing/eloquent-filemaker-test
I also managed to get a shareable Stack trace: https://flareapp.io/share/Lm8AOLjP#F54
The actual FileMaker database isn't relevant here, since the execution fails before the request is sent. The important part is setting DB_CONNECTION=mysql
in the .env
file. When I set this to the name of my FileMaker connection (from the database config file) it works, but I can't do that in my actual project. Thats why I'm using protected $connection = 'filemaker';
in the model class.
I've pushed out a new release which I think will resolve this issue. Please give it a test and let me know if this works for you.
Yep, it works now. Thank you for your help.
I actually have 0.0.21
Il giorno mar 15 mar 2022 alle ore 16:01 Smef @.***> ha scritto:
I thought this was resolved with the 0.0.21 update. Can you check and make sure you have the latest version installed?
— Reply to this email directly, view it on GitHub https://github.com/BlueFeatherGroup/eloquent-filemaker/issues/15#issuecomment-1068088448, or unsubscribe https://github.com/notifications/unsubscribe-auth/AFCDPNW2SCRM6RBU2FZONMDVACQ2VANCNFSM5QYB5PSQ . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.
You are receiving this because you authored the thread.Message ID: @.***>
Hi, don't know if this is an issue or not...
I'm experiencing a fatal error when trying to make the first (simple) query after package installation. What Laravel reports is: "Argument 1 passed to BlueFeather\EloquentFileMaker\Database\Eloquent\FMEloquentBuilder::__construct() must be an instance of BlueFeather\EloquentFileMaker\Database\Query\FMBaseBuilder, instance of Illuminate\Database\Query\Builder given, called in /Users/marco.tognon/Documents/Progetti/Laravel/adam3/vendor/bluefeather/eloquent-filemaker/src/Database/Eloquent/FMModel.php on line 268".
It seems like it's unable to correctly load classes...
Installation via Composer went well, and all other steps made was taken from your Readme. Laravel version is 8.46.0.