PHP Reddit
34 subscribers
297 photos
39 videos
25K links
Channel to sync with /r/PHP /r/Laravel /r/Symfony. Powered by awesome @r_channels and @reddit2telegram
Download Telegram
Architecture decisions for a production Filament 5 app — PHPStan max, strict lazy loading, JSONB custom fields
https://redd.it/1rkqqjc
@r_php
What are you using for your PHP dev setup?

I have decided to shift away from front-end development and get back into PHP. Back in the day I used XAMPP, but since I have moved to Linux and we're living in the future, I wanted to go for something more modern while still keeping it relatively simple.

My goal was to make a rootless Podman container running FrankenPHP in classic mode. That way I would keep the toolchain off the host machine, preventing conflicts between projects using different versions of PHP and also making it easier to recreate the environment. After a bit of a struggle getting it all working, I have realized that VS Code needs PHP for validation and stuff. I have tried making a wrapper that would forward VSC's requests to PHP inside the container, but that ended up being sloooow.

Before burning any more time, I have decided to check around the Internet for what people were using. I have seen Laravel's Sail, Laragon, Lando, DDev and possibly others. However, from my brief examination it looked like they all basically do the same thing I was trying, they just set up some extra tools. I would like to keep the control of doing things manually, and they wouldn't actually solve the VSC/PHP issue as far as I can tell.

So, what are you guys doing? Are you using a container and eating the delay (or is there a solution for that)? Are you developing old-school directly on the host OS (how are you managing PHP versions)? Or is there something else you would recommend?

EDIT: Whew, thanks for all the responses, everyone.

One thing I forgot to mention in the post is that, even though I'm using VS Code for now, I'm trying not to get locked down in proprietary stuff. Attaching to Docker container (which I have conflated with Dev Containers in some comments, my bad) requires a proprietary Microsoft extension. The only equivalent in other editors seems to be in PHPStorm. However, I have now realized that Intelephense doesn't actually rely on a PHP interpreter, which should allow me to sidestep that issue.

Those ready-made container solutions seem to be really popular, so I think I might give Ddev a closer look.

https://redd.it/1rnkta8
@r_php
Deploy & Update automation

TL/DR: what are anno 2026 the best options to automate and manage deploying & updating +200 Symfony application+mysql instances?

A bit of context first: I'm a freelance developer who worked mostly in enterprise environments for the past decade, using multiple techstacks (mostly .NET, node, react, graphQL...) deploying to both on-prem infrastructure using TeamCity as to Azure AKS and some legacy stuff using github actions. But we always had a capable DevOps team handling the config & security setup.
Now I've joined a former colleague who started his own business years ago, who has a software suite and a solid userbase (+200 clients) but his associate & lead dev left and I've agreed to bridge the gap and help him out. I do have +10y experience with PHP Laravel&Symfony though mainly smaller apps & websites, no real scaling experience (I maintain around 10 apps hosted on my own dedicated servers at OVH - lots of headroom costing around 200$ a month).


They currently use Ansible to deploy an application instance-per-client, each with it's own isolated database, but there's no real dashboard or management tool to govern all this.
Now that they continue to scale they are running into issues as it's always the company owner handling deploys & upgrades, lots of manual work. His hosting cost currently runs at 2500-3000$/month.
They are in the middle of stripping out all Laravel dependencies and creating a new version following Symfony8 best practises, but still no (shared runtime) multi-tennant solution - it remains a seperate instance per client and the owner wants to keep it like that.
Looking at average loads etc, it would make sense to put some clients on a seperate VM while other could easily be grouped into 5-10 per server instance.
All clients are local to Belgium & the Netherlands as the application's function is to handle local administration & regulations (also does accounting & erp & process automation etc). Expansion to Germany & France are on the long-term roadmap - expected growth around 25% a year.

What are good options here? Both for hosting as for orchestration & automation tooling.
Free tooling compared to complete PAAS solutions?


https://redd.it/1rou542
@r_php
finally found a bundle that solves Symfony validation the way it should work

been frustrated with validation boilerplate in Symfony for a while, tried a few approaches, nothing felt clean

this one uses JSON Schema as single source of truth — no more scattered constraints, works well with OpenAPI too. prety much validates anything without the usual mess

if ur building APIs with Symfony u probably know the pain. drop a comment if u want the link, happy to share

https://redd.it/1rov8ud
@r_php
Weekly help thread

Hey there!

This subreddit isn't meant for help threads, though there's one exception to the rule: in this thread you can ask anything you want PHP related, someone will probably be able to help you out!

https://redd.it/1rot8d7
@r_php
I wrote a free book about Domain-Driven Design in Laravel

I’ve been using DDD for a long time, so about 3 months ago I wrote a small book about applying it in Laravel. I didn’t publish it right away because I wanted to simplify it as much as possible. I’m not a big fan of heavy theory, so the book is very practical. Enjoy...

https://mayahi.net/books/domain-driven-design-in-laravel

https://redd.it/1rpagd1
@r_php
TIL There's a built-in validation rule in Laravel to check if the user password has been leaked before. I love finding these little gems out of nowhere.

https://redd.it/1rr4s2e
@r_php
Moving from Laravel to Symfony after several years — how hard is it really?

Hi everyone,

I’ve been working almost exclusively with Laravel for several years. Recently I received a really good job offer, but the stack there is based on Symfony.

Over time I’ve moved away from relying heavily on Laravel’s “magic”. In most of my projects I use my own abstraction layers and architecture, and Laravel is mostly used as a boilerplate with routing, Eloquent ORM, and some framework utilities.

Because of that, I’m hoping the transition might not be too painful, but I’m still a bit unsure.

Has anyone here gone through a similar transition from Laravel to Symfony? How difficult was it in practice?

I’d also appreciate any advice on:

* What concepts in Symfony I should focus on first
* What parts usually feel the most unfamiliar for Laravel developers
* Anything that tends to be unexpectedly difficult during the switch

Thanks!

https://redd.it/1rrnqx0
@r_php
99.9% type coverage, PHPStan strict, zero N+1 — building a production CRM in PHP 8.4

Hey r/php, I just shipped v3.0 of an open-source CRM I've been building (Relaticle). Wanted to share some PHP-specific engineering decisions, since this community appreciates that kind of thing.

PHP 8.4 strict mode in production: Every class is final. Every file uses strict_types. Typed properties and return types everywhere:

declare(stricttypes=1);
final class People extends Model implements HasCustomFields
{
/** @use HasFactory<PeopleFactory> */
use HasFactory;
use HasUlids;
use SoftDeletes;
use UsesCustomFields;

/** @var list<string> */
protected $fillable = ['name', 'creation
source'];

/ @return BelongsTo<Company, $this> /
public function company(): BelongsTo
{
return $this->belongsTo(Company::class);
}
}

Spatie's laravel-data for typed DTOs:

final class SubscriberData extends Data
{
public function __construct(
public string $email,
public ?string $first_name = '',
public ?string $last_name = '',

# PHP 8.4 with strict_types everywhere is genuinely a joy to write. The language has come so far.

99.9% type coverage: I run PHPStan at level 7 (via Larastan). Every method signature is typed. Every return type is explicit. CI fails on any violation — no exceptions, no baselines.

/
@param Collection<int, Contact> $contacts /
public function processImport(Collection $contacts): ImportResult
{
}

# Is it overkill? Maybe. But in a CRM where data integrity matters (contacts, deals, money), catching type mismatches at static analysis time is cheaper than catching them in production.

N+1 query prevention: One line in AppServiceProvider:

Model::preventLazyLoading(!app()->isProduction());

# Strict lazy loading enabled globally. Forget an eager load? Exception in development. This alone caught 10-20 performance issues before they shipped.

PostgreSQL over MySQL: Migrated from MySQL to PostgreSQL 17+ in v3.0. Key reason: JSONB. I built no-code custom fields — users create fields without touching code. All stored as JSONB with GIN indexes:

-- PostgreSQL JSONB with proper indexing
CREATE INDEX idxcustomfields ON contacts USING GIN (customfields);
-- Partial path queries that MySQL JSON can't do efficiently
SELECT * FROM contacts WHERE custom
fields->>'industry' = 'SaaS';

# MySQL's JSON type can't do proper indexing or partial path queries at this level. For a CRM with dynamic schemas, PostgreSQL is the better fit.

Testing with Pest: Comprehensive test suite — unit, feature, and browser tests. Pest's syntax makes test writing feel less like a chore:

arch('strict types')
->expect('App')
->toUseStrictTypes();

arch('avoid open for extension')
->expect('App')
->classes()
->toBeFinal();
});

# Architecture tests prevent structural issues at CI time. If someone accidentally breaks a convention, CI catches it.

Import wizard (the hardest problem): Real-world CSVs are chaos:

Automatic date format detection (uses Laravel's date validator under the hood)
Fuzzy + exact column matching
Relationship mapping (person → company linkage)
Chunked processing for large files
Granular error reporting (which rows failed, why) If anyone's solving CSV import in PHP, happy to discuss approaches.

Stack:

PHP 8.4 + Laravel 12
PostgreSQL 17+ + Redis
Filament 5 + Livewire 4
Docker + docker-compose Links:
GitHub: https://github.com/Relaticle/relaticle (1.2K stars)
Free hosted: [https://relaticle.com](https://relaticle.com) (no credit card)
License: AGPL-3.0. For internal use — no restrictions.



What PHP 8.4 features have you found most useful in production? Curious what patterns this community is adopting

https://redd.it/1rru8yy
@r_php
Appel à settings/password depuis mon front SPA Nuxt

Hello,

mon front SPA Nuxt fait un appel PUT à l'endpoint de Laravel Fortify /settings/password lorsque le user connecté veut modifier son mot de passe depuis son dashboard. Le mot de passe est bien enregistré mais la réponse est une redirection alors que je veux que ce soit une réponse JSON avec un message de succès ou d'erreur.
Comment faire ?
Merci

Voici mes bouts de code:

Fonction appelée par le formulaire:

const resetPassword = async () => {
loading.value = true

try {
const data = await api('/settings/password', {
method: 'PUT',
body: {
currentpassword: currentPassword.value,
password: password.value,
password
confirmation: passwordConfirmation.value,
}
})
status.value = 'success'
message.value = 'Mot de passe modifié avec succès'
currentPassword.value = ''
password.value = ''
passwordConfirmation.value = ''
} catch (err: any) {
console.log(err);
status.value = 'error'
message.value = err.data?.message || 'Une erreur est survenue'
} finally {
loading.value = false
}
}

Le composable useApiFetch:

export function useApiRequest() {
const config =
useRuntimeConfig
()
const xsrfToken =
useCookie
('XSRF-TOKEN')

return
$fetch
.create({
baseURL: config.public.apiBase,
credentials: 'include',
headers: {
'Accept': 'application/json',
'X-XSRF-TOKEN': xsrfToken.value || '',
},
})
}

La Response de l'appel à l'endpoint contient un Header Location qui entraîne la tentative de redirection.




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