PHP Reddit – Telegram
PHP Reddit
34 subscribers
289 photos
37 videos
24.8K links
Channel to sync with /r/PHP /r/Laravel /r/Symfony. Powered by awesome @r_channels and @reddit2telegram
Download Telegram
assetMapper and fonts

Hi,

I'm trying to import a google font.

php bin/console importmap:require @fontsource/oswald

This works fine, but after, i need to replace this with the local version, in my css

import url('https://fonts.googleapis.com/css2?family=Oswald:wght@200..700&display=swap');

i've tried

@import url('@fontsource/oswald/index.min.css');

or

@import url('@fontsource/oswald');

But it does not work..

How can i do that ?

https://redd.it/1miy6l1
@r_php
Configuring Renovatebot for upgrading Symfony?

I'm setting up Renovatebot to update my packages in a Symfony app, but i'm a bit confused about the Symfony packages.

I want to make a group so it will update them all together when doing Symfony upgrade. But how to make it change this part? eg. when upgrading from 7.2 to 7.3

"extra": {
"symfony": {
"allow-contrib": false,
"require": "7.2.*"
}
}

https://redd.it/1mj6r1f
@r_php
Learning Symfony & Twig: Components, Conventions, and IDE Pains

Hi everyone,

I'm currently learning Symfony and Twig, and I’ve run into a few questions regarding best practices for structuring Twig components and improving developer experience. I’d really appreciate your input:



1. Where should I place Twig components ? I already have a folder structure for my templates, so if I need to move everything into a specific folder, that could be inconvenient.
2. What’s the convention for distinguishing between PascalCase and kebab-case? (I get the impression that everything that isn’t a class is written in kebab-case. However, in the case of templates vs TwigComponents, this creates a bit of an awkward inconsistency. So I’m not sure if I can use PascalCase for everything, or if I should keep using kebab-case for templates that aren't Twig components.),
3. Is it forbidden to have files prefixed with an underscore? Do they always have to start with a letter, or sometimes even an uppercase letter?,
4. What’s the naming convention regarding the “s” at the end of file or folder names? For example, sometimes we see "templates" (with an “s”), but for "api", it's usually singular.,
5. I’m working on VS Code, but auto-import doesn’t work, and incorrect paths aren’t being detected either. Yet I’ve installed all the recommended extensions, including PHP Intelephense and PHP Namespace Resolver, and according to various LLMs, my settings.json is correctly configured. Another feature that would be interesting is automatic reference updating when a file is moved. Is that even possible in PHP/Twig?, I’ve seen quite a few similar issues online — some people recommend switching to PhpStorm, which apparently has fewer problems. Would that really be the better solution?
6. Is there a GitHub repository that shows a realistic example of best practices and usage of Twig components?

Thanks in advance for any guidance, tips, or resources. 🙏

https://redd.it/1mjb92n
@r_php
Symfony vs Laravel

The post "Symfony vs Laravel - Understanding the Differences" on kodmatrix.com is an insightful resource for developers who want to compare these two leading PHP frameworks. It highlights key aspects such as learning curve, performance, modularity, scalability, and ease of use.



https://redd.it/1mjfj2z
@r_php
Magicless PHP framework?

First I'd like to say that I have nothing against the modern frameworks full of reflection and other dark magic, but I'm wondering if there's a PHP framework that is rather explicit than implicit in how it works, so that I don't need extra editor plugins to understand things such as type hints or what methods a class has.

Laravel, while great, often feels like programming in a black box. Methods on many of the classes don't exist (unless you use PHPStorm and Laravel Idea, or other extra plugins), data models have magic properties that also don't exist, and so on and so on, which makes me constantly go back and forth between the DB and the code to know that I'm typing a correct magic property that corresponds to the db column, or model attribute, or whatever ... and there's a ton of stuff like this which all adds up to the feeling of not really understanding how anything works, or where anything goes.

I'd prefer explicit design, which perhaps is more verbose, but at least clear in its intent, and immediately obvious even with a regular PHP LSP, and no extra plugins. I was going to write my own little thing for my own projects, but before I go down that path, thought of asking if someone has recommendations for an existing one.

https://redd.it/1mjvdxw
@r_php
How do you handle exceptions which you expect not to be thrown?

This question bugs me for a long time.
Often times an exception could be theoretically thrown but this will never happen in practice because the codepath is basically static.
Thats also wouldnt be a Problem if IDEs like PHPStorm wouldnt warn you about every unhandled exception through the complete stack trace.

So what patterns are you using to handle stuff like `DateMalformedException`, `RandomException` etc. which you no wont throw and if so it should crash.

For example given the following method:

/**
* @return $this
* @noinspection PhpDocMissingThrowsInspection // if removed doccomment also triggers warning
*/
public function expire(): self
{
$this->expirationDate = new DateTime();
$this->expirationDate->modify("-1 day"); // Unhandled \DateMalformedStringException

return $this;
}

Because the values are static you can expect that it works. More dynamic example would be:

function addDays(DateTime $date, int $days): DateTime
{
$date = clone $date;
$date->modify("+$days days"); // Even in this case we can safely assume the format is always correct because days is an int.
return $date;
}

Another candidate is `random_int`

random_int(1, 10); // Unhandled \Random\RandomException

https://redd.it/1mk3xzd
@r_php
Newbie learning to educate myself

Hey everyone!

I'm a bit new to the programming world (besides a few classes in early college years) and was wanting to start my journey into programming with PHP.

Why?
Well, I work closely with the owners of a photography business who commissioned a photo album app with compression and all this other stuff from someone on Upwork but, none of them really know the behind the scenes as it relates to the code.

It's still in development but what they're using is SQL, cloudflare R2, and laravel so I was hoping to get educated enough to at least have some degree of experience with keeping things in line (long, long road from doing anything but, it at least would give us some understanding of what we're looking at besides just being the just app users).

So, my question is, is there a best way to help educate myself on these topics to be somewhat competent and help out once the app is complete? I know it will be a long road, but I'm up for it!

Thanks!

https://redd.it/1mk6ggp
@r_php
Camel case vs snake case inconsistency

How do you guys deal with camelCase and snake_case inconsistencies?
I'm particularly interested for object properties. I know the usual suggested way is camelCase, but when your db columns are in snake case it can get a bit confusing to see db queries with snake_case column names (also array indexes), but then use camelCase when accessing it as an attribute of the object. Similarly a lot of api objects use snake_case as well...

I'm curious how others deal with this

https://redd.it/1mk92hm
@r_php
File-based Routing Microframework Based on HttpKernel
https://zack.tebe.ch/

https://redd.it/1mkk412
@r_php
🌍 GeoIP Bundle by ndevs.eu

🆕 New Symfony Bundle just dropped!


Detect geolocation from IP address with ease 🚀
Supports MaxMind & IP2Location (with optional fallback)
✔️ Clean config
✔️ Auto-injected into request
✔️ Perfect for CDNs, proxies & mock IPs in dev

📦 composer require ndevs-eu/geo-ip-bundle


🔗 https://github.com/ndevs-eu/geo-ip-bundle

Open-source & production-ready 💪
\#symfony #php #opensource #devtools #geoip #ndevs

https://redd.it/1mkqowy
@r_php
Symfony LiveProp and mapping adjusted ManyToMany collection.

Howdy,

I've been experimenting with Symfony and UX LiveComponents + Mercure in order to create a digital character sheet for my roleplaying group. By combining LiveComponent events and listening for updates via Mercure I managed to get Real-Time updates between two sessions to work.

My initial test was a simple string value stored for each character to represent their name, and I instantly hit a snag when trying to use a more complex variable as a LiveProp.

Each character has a variable amount of attributes assigned to them (since not every character has every attribute), so my Schema looks like this:

Character (id, name)

Attribute (id, name)

Character_Attribute (id, character_id, attribute_id, value_current, value_max)

The reason I call it an Adjusted ManyToMany is because each attribute has a current and max integer value that is unique to each character, so instead of using the ManyToMany doctrine mapping I've created a separate entity called CharacterAttribute which is mapped ManyToOne Character and ManyToOne Attribute.

So Symfony sees the following:

CharacterAttribute.php
    #ORM\ManyToOne(inversedBy: 'Attributes')
    #ORM\JoinColumn(nullable: false)
    private ?Character $character = null;

    #ORM\ManyToOne
    #ORM\JoinColumn(nullable: false)
    private ?Attribute $attribute = null;
-------------------------------------------------------
Character.php
/
@var Collection<int, CharacterAttribute>
/
#ORM\OneToMany(targetEntity: CharacterAttribute::class, mappedBy: 'character', orphanRemoval: true)
private Collection $Attributes;

I pass a Character variable to a LiveComponent twig.php-file where it is listed as a #[LiveProp(writable:['name'\])\]

I can access the PersistentCollection of attributes for each character without issue in for example twig-templates by looping over Character.Attributes, but here are the issues I have encountered.

Test 1: LiveProp writable attribute

If I add the Attributes property of the Character Entity to the #[LiveProp(writable:['name', 'Attributes'])] attribute that is assigned to a Character variable in the twig.php-file I get the following error:


An exception has been thrown during the rendering of a template ("The writable path "Attributes" on the "character" property of the "App\Twig\Components\Character\GetAttributes" component must be a scalar or array of scalars.")

I assume since the Attributes property is a Collection<int, Character_Attribute> that is is too complex to dehydrate.

Test 2: Free-standing LiveProp

If I add the CharacterAttributes entity as its own variable to the twig.php-file like this:

#[LiveProp(writable:true)]
public CharacterAttributes $attributes;

Then I get this error message:

An exception has been thrown during the rendering of a template ("Expected argument of type "App\Entity\CharacterAttributes", "Doctrine\ORM\PersistentCollection" given at property path "attributes".")

So I change the variable type to PersistentCollection instead.

An exception has been thrown during the rendering of a template ("The "owner" property on component "App\Twig\Components\Character\GetAttributes" is missing its property-type. Add the "App\Entity\Character" type so the object can be hydrated later.")

Test 3: LiveProp writable(true)

I tested changing the Character #[LiveProp\] attribute from

#[LiveProp(writable['name'])

to

#[LiveProp(writable:true)]

To make the entire Character entity writable. I don't get an error message this time and I can even access the Attributes property in my Twig-component by writing: {{ Character.Attributes }}

I could even loop through everything but I have been unable to map the individual attributes inside the Attributes variable to Live inputs. For example, in the following code I can access the valueCurrent property from attribute which comes from {% for attribute in this.Character.Attributes %} and
output it, but when I do this, I cannot update any property on the Entity (not even the name property I could edit before).

<div>
{{ attribute.valueCurrent }}
<input data-model="on(change)|attribute.valueCurrent" data-action="change->live#action" data-live-action-param="saveChanges">
</div>

Now I think I know why this is, and that is because there is no LiveProp-ed variable in the twig.php-file matching the name "attribute". Is it possible to edit individual entities inside a LiveProp-ed collection?

Now

This is where I've hit a dead-end. In addition to above I've tried to create a DTO-class to hold the data, but got the same error message as Test 2. I've tried to hydrate/dehydrate with custom functions, and I managed to get it to dehydrate, but found no way to rehydrate the values back to the Character entity.

So my question is has anyone here tried to use LiveProp/LiveComponents with "complex" entities like this before?

Is it even possible to use LiveProp with a PersistentCollection like this or should I resign myself to using something like UX Turbo and forms?

https://redd.it/1mkqwji
@r_php
Filament v4 is launching on Tuesday, August 12th!

The FilamentPHP team [announced the release date](https://x.com/filamentphp/status/1953574144098127972) for Filament v4 yesterday. Lots of meaningful improvements for performance, DX, and customization. You should check out the [great overview](https://filamentphp.com/content/leandrocfe-filament-v4-beta-feature-overview) posted by Leandro Ferreira but a few highlights of v4 are:

* Performance: Large tables render 2–3x faster.
* Tailwind v4: Modernized theming with oklch colors.
* Auth: Built-in MFA (TOTP apps + email codes).
* Resources: Nested resources and better organization.
* Forms: New TipTap rich editor, slider, code editor, table repeater, partial rendering, and JS hooks to reduce network requests.
* Tables: Custom data sources (no DB required), better bulk actions, reorderable columns.
* Actions: Unified actions across tables/forms/infolists with rate limiting and better testing.
* Panels: Strict authorization mode, local Inter font, improved error notifications.
* Theming: CSS improvements have made theming significantly easier. There are great themes available at [https://filamentthemes.com/](https://filamentthemes.com/) and [https://filafly.com/](https://filafly.com/) as well as many other community options being released on Discord or the [Filament Plugin](https://filamentphp.com/plugins) page.

What feature are you most excited to try first? Are you planning to upgrade right away or wait for a while post launch?

https://redd.it/1mkvmg7
@r_php
insight about my portfolio

Hello everyone!

so i've been learning and learning from online resources and with aid of various LLM's php/laravel/mysql/js/react/docker, and i've managed to get by into doing a sort of self-assessment/hands on learning projects that i thought would be helpful with landing me an entry level/junior position anywhere remotely, but it seems like i keep getting rejected over and over, and im not sure if the market expects something more or something else entirely, i tried to create a couple of projects that demonstrates my level of knowledge at this point, my GH here has them: https://github.com/Abdu-Ahmed ,,, am i doing this wrong? should i pause the job hunting and work on a specific aspect? im not sure and quite frankly i feel lost, any insight and or advice is much needed.

Thank you!

P.S i do NOT have any relevant work exp and a drop out so yeah, you can guess how difficult it is :/

https://redd.it/1mkwa7w
@r_php