Chapters
48 Chapters
|
5:13:28
|
Login to bookmark this video
-
Course Code
Subscribe to download the code!
Subscribe to download the code!
-
This Video
Subscribe to download the video!
Subscribe to download the video!
-
Subtitles
Subscribe to download the subtitles!
Subscribe to download the subtitles!
-
Course Script
Subscribe to download the script!
Subscribe to download the script!
25.
Custom Filter, getDescription() & properties
Scroll down to the script below, click on any sentence (including terminal blocks) to jump to that spot in the video!
Subscribe to jump to this part in the video!
Keep on Learning!
If you liked what you've learned so far, dive in! Subscribe to get access to this tutorial plus video, code and script downloads.
This tutorial also works great with API Platform 2.6.
What PHP libraries does this tutorial use?
// composer.json
{
"require": {
"php": ">=8.2",
"ext-ctype": "*",
"ext-iconv": "*",
"api-platform/core": "^2.1", // v2.5.10
"composer/package-versions-deprecated": "^1.11", // 1.11.99
"doctrine/annotations": "^1.0", // 1.12.1
"doctrine/doctrine-bundle": "^2.0", // 2.1.2
"doctrine/doctrine-migrations-bundle": "^3.0", // 3.0.2
"doctrine/orm": "^2.4.5", // 2.8.2
"nelmio/cors-bundle": "^2.1", // 2.1.0
"nesbot/carbon": "^2.17", // 2.39.1
"phpdocumentor/reflection-docblock": "^3.0 || ^4.0 || ^5.0", // 5.2.2
"ramsey/uuid-doctrine": "^1.6", // 1.6.0
"symfony/asset": "5.1.*", // v5.1.5
"symfony/console": "5.1.*", // v5.1.5
"symfony/debug-bundle": "5.1.*", // v5.1.5
"symfony/dotenv": "5.1.*", // v5.1.5
"symfony/expression-language": "5.1.*", // v5.1.5
"symfony/flex": "^1.1", // v1.21.6
"symfony/framework-bundle": "5.1.*", // v5.1.5
"symfony/http-client": "5.1.*", // v5.1.5
"symfony/monolog-bundle": "^3.4", // v3.5.0
"symfony/security-bundle": "5.1.*", // v5.1.5
"symfony/twig-bundle": "5.1.*", // v5.1.5
"symfony/validator": "5.1.*", // v5.1.5
"symfony/webpack-encore-bundle": "^1.6", // v1.8.0
"symfony/yaml": "5.1.*" // v5.1.5
},
"require-dev": {
"doctrine/doctrine-fixtures-bundle": "^3.3", // 3.3.2
"symfony/browser-kit": "5.1.*", // v5.1.5
"symfony/css-selector": "5.1.*", // v5.1.5
"symfony/maker-bundle": "^1.11", // v1.23.0
"symfony/phpunit-bridge": "5.1.*", // v5.1.5
"symfony/stopwatch": "5.1.*", // v5.1.5
"symfony/twig-bundle": "5.1.*", // v5.1.5
"symfony/web-profiler-bundle": "5.1.*", // v5.1.5
"zenstruck/foundry": "^1.1" // v1.8.0
}
}
10 Comments
Hi,
if I need to decorate the name of the parameter for a nested resource do I need to create a Custom filter or there is a simple way to do so?
I would like to have this parameter as
api/partnerRestriction?restriction=testand not
api/partnerRestriction?partnerRestrictionTag.value=testHey there,
That's a good question, and after looking at the ApiPlatform documentation, I didn't find a way to configure filter names. I think the only way to do that is by creating a custom filter, unless I missed something
Cheers!
If someone have troubles with Absctract Filter - use AbstractContextAwareFilter
Hey Anton B.
Good tip, but what troubles can be found here?
Cheers|!
Hi,
i'm trying to filter on computed values, i created a custom filter
There is no property stockAvailable just a method :
but the filter seems not working, i wonder if my case is possible
Hey Joel L.
First, you will have to create a custom filter and hook it into the ApiPlatform system
https://api-platform.com/do...
Then, you'll have to code the right query to perform the filtering you require. I believe the code you wrote will work, the only thing you're missing is the query identifier you set at the moment of creating a `QueryBuilder`
Let me know if it worked. Cheers!
Actually i already try based on this example.
BTW the API Platform doc example is slightly different from the SFCast course. One is extending AbstractContextAwareFilter and the other one AbstractFilter, does it matter ?
I forgot to mention i'm using GraphQL
Those two abstract classes are almost the same, the only thing that changes is on the
apply()method theAbstractContextAwareFilteradds an extra argument to the function, the$contextargument, if your filter requires the $context to operate, then you will have to extend from that class, otherwise you can extend from the other oneI'm not sure if all of this applies to GraphQL but I'd assume it does
Hello,
how can we type these properties in yaml configuration ?
thanks
Hi Abdelkarim,
If you go to this URL: https://api-platform.com/docs/core/filters/#doctrine-orm-and-mongodb-odm-filters and click on the YAML tab for its examples, you will find ways to do this using yaml. Hope it helps!
"Houston: no signs of life"
Start the conversation!