gearbox-solutions / eloquent-filemaker

A Model extension and Eloquent driver for Laravel connecting to FileMaker through the Data API
https://gearboxgo.com
MIT License
54 stars 16 forks source link

Filament Table-Builder integration with Eloquent-FileMaker #67

Closed qt2git closed 3 months ago

qt2git commented 3 months ago

Dependencies

Description of the issue:

The basic integration of filament table-builder with eloquent-filemaker works so far. That means, I get a table filled with records from a FileMaker database. Unfortunately all dataset manipulations, such as filtering, sorting and searching fail.

Excerpt of the exception: `array:61 [▼ 0 => array:6 [▼ "file" => "vendor/livewire/livewire/src/Mechanisms/ExtendBlade/ExtendedCompilerEngine.php" "line" => 58 "function" => "handleViewException" "class" => "Illuminate\View\Engines\CompilerEngine" "type" => "->" "args" => array:2 [▼ 0 => Illuminate\View \ ViewException {#1345 ▼

message: "Value list is missing (View: /Users/me/Sites/app/vendor/filament/tables/resources/views/index.blade.php)"

    #code: 0
    #file: "

/Users/Sites/app/vendor /gearbox-solutions/eloquent-filemaker/ src/Services/FileMakerConnection.php"

line: 137

    -previous: 

GearboxSolutions\EloquentFileMaker\Exceptions \ FileMakerDataApiException {#2612 ▶}

severity: E_ERROR`

Expected Behavior:

Database manipulations such as filtering, searching and sorting should work as with sql database queries.

Have you successfully implemented filament table-builder with eloquent-filemaker before? Do you have a tip how to make it work? Thanks for your help and best regards. Martin

Smef commented 3 months ago

The error you're getting is a Data API error From FileMaker: "Value list is missing". Is there a value list on that layout, possibly set as an autocomplete on a field or something, which may have have been deleted?

This is Error 108.

qt2git commented 3 months ago

Thank you for your answer. There is no VALUE List neither on the FileMaker layout, the view nor in the component - nothing. When clicking on a column to sort or search a string and the error occurs, the excpetion list in the debugbar (barryvdh/laravel-debugbar) ist quite long (about 60 items with many collapsed sections). When I retreive the records from a sqlite database and use one of the filter mehods everything works fine. Can I send you a log to get more insight? If yes, which one?

Smef commented 3 months ago

If you install Clockwork and check the database query log you should be able to see which query is giving you the error. The error you have is from the Data API, so seeing the request which is causing the error may give some more insight.

qt2git commented 3 months ago

I do not even get to the database query. It throws a 500 and stops right away.

2024-05-24_16-15-02
Smef commented 3 months ago

The queries will show in the log tab.

qt2git commented 3 months ago

Still no database queries....

2024-05-24_16-23-16
Smef commented 3 months ago

Sorry, it's actually supposed to be the database tab. Is that showing up for you?

If it's not there, you may need to update Eloquent FileMaker to the latest version so that the queries are captured.

You should see a tab like this:

Screenshot 2024-05-24 at 2 42 43 PM

qt2git commented 3 months ago

Thanks for your hints! I set up a new project with the latest (newest) extensions (such as Eloquent-FileMaker, Jetstream-FileMaker v2.x). So far it works a lot better (at least sorting works), but I cannot search the table. In clockwork I now get a database tab.

2024-05-28_14-45-25

What needs to be done to also be able to search in a table?

Smef commented 3 months ago

It looks like you're trying to use FileMaker as your cache driver. That's probably not going to work well, and you should change your cache driver to 'file' or something else.

If you do have a SQL database, you can use that, but your'll need to update your cache config so it doesn't use your FileMaker connection.

qt2git commented 3 months ago

I configured to use a sqlite database. The sqlite database works out of laravel (can migrate tables) and the query that is created from a search filter (query) in filmanet works in the sqlite database as well. But still, the clockwork log seeams to try to use the FileMakerConnection.php

2024-05-28_17-09-48

Is there an eloquent config as well that needs to be changed?

Smef commented 3 months ago

No, this is a Laravel config issue. As you can see, it's trying to run a sql query on your FileMaker connection to retrieve cache data. It looks like your FileMaker database is set as your cache driver.

Smef commented 3 months ago

Someone else recently commented about a similar issue which was related to cache config as well. The env value for the cache config changed in Laravel 11, which may be what's throwing you off here as well.

Be sure you have CACHE_STORE=file set in your .env. Redis would also be fine. The .env value is different between Laravel 11 and 10.

qt2git commented 3 months ago

I do not think it's a CACHE problem (anyway, I did configure the cache also in .env), because the cache record is being created. But what puzzles me is that there ist no query at all when using eloquent-fm.

Example with SQLITE: filament table search

2024-05-29_08-45-05

Example with eloquent-FM: filament table search

2024-05-29_08-49-27

In the latter example there is no POST request at all. That's why the data-object is empty. I hope there is a solution for this. Would be too bad, if this last bit can not be solved....

Smef commented 3 months ago

There is a solution, and the solution is to change your cache driver to something other than 'database' so that FileMaker is not being used for your cache.

The first thing Eloquent FileMaker is trying to do is get the session key from your application's cache. This is failing because FIleMaker is being used for the cache.

There is an attempted post request, but it's hitting an error because SELECT * from "cache" is a SQL query, not a valid format for the FileMaker data API. You can see that it's trying to read from the cache table.

Your SQLite database has a cache table and SQL is valid format to make a query against a SQLite database. Executing this does not cause an error and allows the rest of the queries to run. You can see that your first request is in the "DisableBackButtonCacheMiddleware" which also appears to be cache-related.

Your FileMaker database does not have a cache table and SQL is not a valid format to make a query to the FileMaker Data API. Attempting to read cache data from FileMaker causes an error and prevents the rest of the queries from running.

This will not function until you change your cache driver to something other than "database".

When your database is SQLite, SQLite is also being used to for the cache because your cache driver is set to 'database'.

When you change the database to FileMaker, FileMaker is also being used for the cache because your cache driver is set to 'database'. The cache driver does not format the query properly for the FileMaker data API.

The screenshots that you are posting are very clearly showing that the problem is that your cache is configured to use the database.

This will not work until you change the cache driver.

qt2git commented 3 months ago

I tried all availalbe cache driver options, file and array as well. But unfortnuately without success or more insight. When the cache option is set to file a cache-file is being created in the storage-path. Works so far. But when a search query is set in the filament table, it does not even create a query:

2024-05-30_15-50-22

Somehow it seems, that it does not even get to the point where it posts the query. From the clockwork-log I do not see where it's stuck or what the cause is. Do you?

Smef commented 3 months ago

The screenshot you posted shows that your application is trying to retrieve cache data from your FileMaker database. This means that your FileMaker database is being used for your cache, and that you have not configured the cache correctly. You can see that it is trying, and failing, to use FileMakerConnection.php as the source of the cache data.

Your cache driver/store is not configured properly.

Smef commented 3 months ago

Before every request to the database, Eloquent FileMaker tries to get an existing session token from your cache.

Your app appears to be erroring on this request to the cache, which is why you aren't seeing any queries to the database.

You may want to just do a regular query to your FileMaker database as a test, rather than using Filament to do this stuff. Make a model and do a query. It seems like you'd get the same error with that and see no query executed, as it appears to be failing to retrieve data from the cache.

qt2git commented 3 months ago

The application without filament works well. Here is an example with a search request via livewire with the exact same application (no filament in this view):

2024-05-30_16-52-24

The call to the cache is exactly the same as in the example with filament.

In Laravel 11 cache_driver is renamed to cache_store. I set the cache_store in the .env, and overwrote the default values in config/cache to only use file. But it does not help at all.

Smef commented 3 months ago

Hmm... so that one is working. Is there something in Filament which could be forcing it to use the FileMaker connection for the cache?

Can you post the full stack trace?

Smef commented 3 months ago

The error you were getting "Value list is missing" is a Data API error, so you could also possibly put a breakpoint in FileMakerConnection line 137 to see what the actual query is which is being executed there, which may help you diagnose why the Data API is complaining.

The Data API is bad at giving information about why it's unhappy, unfortunately, but you can check the layout which is being queried.

qt2git commented 3 months ago

On the line 137 in FileMakerConnection.php it builds the URL for the API which works (I get the correct endpoint):

2024-05-31_17-25-52

In the Developer Tools I get the following error:

2024-05-31_17-22-16

As the inital query to build the table works and the error only occurs on filtering/search the generated table, it's not possible to break the query in between to see what happens on a search query.

Smef commented 3 months ago

FileMaker Connection.php line 713 should catch which actual endpoint is being hit in the $url variable, which will also include the FileMaker layout which you're using. This will also have the post data as the $params variable for seeing if there is anything be sent about value lists.

Smef commented 3 months ago

I just pushed up 2.3.2 which modified the error messages to always include the layout name. This may help diagnose the layout with the issue. I recommend updating to that version and triggering the error again.

qt2git commented 3 months ago

Thanks for your support. The $url variable from the makeRequest method contains the correct path to the filemaker Data API / Layout.

The $params array holds the following data:

2024-06-03_11-09-59

In the "wheres" the correct query is visible.

The $response (~ line 715) looks like this:

2024-06-03_10-20-33
Smef commented 3 months ago

The error "Value list is missing" is coming from the FileMaker Data API. There's something on the layout which is missing a value list. I'm not sure if it's something related to your sort, a calculation, the particular found records, or one of the fields being used, but somewhere on the layout being used is something dependent on a value list which is not available for at least one record.

You can try running this same query manually in something like Postman, with the same layout, sort, and find fields if that makes it easier for you to diagnose it.

It could be a permissions issue for the user which you are using for your web app as well. You may need to check and make sure that the user's permissions allow has access to the value lists.

Alternatively, you may need to try remove some of the fields from the layout to find out which is causing the error. Unfortunately the FileMaker Data API is very poor at giving feedback about this stuff.

There isn't anything in the package here which can be changed or updated to resolve this, and this isn't a bug with Eloquent FileMaker.