PHP Reddit – Telegram
PHP Reddit
34 subscribers
293 photos
37 videos
24.9K links
Channel to sync with /r/PHP /r/Laravel /r/Symfony. Powered by awesome @r_channels and @reddit2telegram
Download Telegram
I created a D&D character API using PHP and Laravel

For the past couple of months I've been building out an API to create and manage D&D characters using the 5E rules. I originally created it just as a learning tool (I'm a developer by profession, but out of work at the moment, the market hasn't been great recently) but I envisage it as an alternative (one day) to many of the bigger paid-for services out there, as it's completely free and has no restrictions.

Currently, the API allows you to:

* Create characters, and set their class, background, race, languages, stats, spells
* Get race-specific name suggestions (not AI, but a custom Markov chain generator)
* Roll dice from the standard 6 types (d4 - d20)
* Generate creature encounters based on a party of characters (limited to a party of a single user currently, but I can adapt this to allow a mix of characters from many users in the future)
* Generate random items, from armor and weapons, to books and gemstones. There is even a small chance to generate magical items!

There are also endpoints for listing out general things like classes, races, languages, spells, and more.

The whole API has a Postman collection to help make it easier to work with as well, and I've documented it on the homepage of the API website.

The API is available at: https://dndapi.ashleysheridan.co.uk/



https://redd.it/1j875qd
@r_php
Fadogen Build and deploy, easily - now open source

Hello everyone, I'm back with updates about my Fadogen project. I've spent almost an entire month working on it since my first post about it. Lots of new features to share with you.

The first and most important update is that the project is now open source:

https://github.com/fouteox/fadogen

This gives you the option to use it locally. But you can still use the website if you prefer: https://fadogen.app

First, as a reminder, Fadogen allows you to initialize applications very easily using Docker and DDEV.

# What's changed since last time?

I've added the ability to deploy self-hosted applications on a Raspberry Pi just as easily (I hope) as initializing them. All this is thanks to Cloudflare tunnels, so without opening any ports on your router. The only prerequisite is having a domain name on your Cloudflare account (you don't even need to configure it).

# Let me explain what happens under the hood

When you initialize an application with Fadogen, you choose different options such as:

\- A database
\- A starter kit
\- Your preferred JavaScript package manager (npm or bun)
\- Horizon with Valkey or Redis
\- Reverb
\- Octane with FrankenPHP

Based on all your choices, Fadogen configures what's necessary for development, but now also for production. Here's everything that's generated for you according to your choices:
\- compose.production.yaml
\- Dockerfile
\- Caddyfile
\- Several supervisor files
\- .env.production
\- A GitHub action file

You don't have to configure anything manually.

Once you're ready to deploy your application, the next step is to run the following command at the root of your project: `ddev prepare`

This is a DDEV add-on that's automatically added to your project during its initialization.

# What does this add-on do?

First, I want to clarify that everything now happens locally, nothing is sent to Fadogen from this point on.

It will ask you several questions in your terminal:
\- It will ask for your Cloudflare email and API key
\- An API call is made to your account to retrieve the domain names linked to your Cloudflare account
\- These domain names are listed and you need to select one
\- Then, the username and local address of your Raspberry Pi is requested
\- Next, you'll be invited to connect to your GitHub account via the CLI

From there, you're definitely done with the "configuration" part. The add-on takes care of the rest.

It will handle adding to your GitHub repository all the secrets that the GitHub workflow will need for deployments:
\- The .env.production file encoded in base64
\- The UID, GID, and username of your Raspberry Pi
\- The SSH address of your Raspberry Pi
\- The remote hostname
\- Your private SSH key for deployments

Now, one last part of the noscript will trigger automatically.

This step configures your Raspberry Pi to install Docker, add your user to the Docker group, install the "cloudflared" tool to enable Cloudflare tunnel usage, make API calls to your Cloudflare account to create the tunnel and redirect traffic from the domain name to your Raspberry Pi, and also create a secure SSH tunnel that will be used in the GitHub action.

A Traefik container will also be created as a reverse proxy to route traffic to the correct containers.

Once everything is done, you're ready!

The next step now lies in GitHub actions. This will trigger with each merge into the main branch or manually via the GitHub interface.

This GitHub action connects to your Raspberry Pi thanks to the Cloudflare tunnel and deploys the new version of your application.

# What should I do to try the tool?

\- [ \] Initialize a project from https://fadogen.app or by cloning the project locally
\- [ \] Have a domain name registered with Cloudflare
\- [ \] Set up a Raspberry Pi (Pi 5 and 4GB recommended) by adding your public SSH key when flashing the SD card (SSD preferred)
\- [ \] Get your Cloudflare API key =>
Profile => API Tokens => Global API Key. It's normally better to use a specific token but there's currently a bug retrieving domain names; I created a topic on the Cloudflare forum (https://community.cloudflare.com/t/authentication-issue-with-api-tokens-when-accessing-cloudflare-registrar-domains/776526/1)
\- [ \] Run the command "ddev prepare" and follow the instructions!

# Why create Fadogen?

Today, the recommended way to create a Laravel application is to use Herd. You can use the free version but if you don't have knowledge about databases, Redis, and Reverb, you need to pay for the pro version: $99 per year.

Now you want to host your application? You need to select a VPS like Hetzner, Digital Ocean, AWS... $5 per month on average.

You now want to deploy the application ? Opt for Laravel Forge: $12/month (or Ploi for $8).

Add a domain name: $10 per year.

Total: $313

I'm not criticizing these tools; I've used them myself and they do the job very well, but for small and medium projects or for quick testing, this can be too expensive.

With Fadogen, you only pay for the domain name and the Raspberry Pi purchase (but in theory, it should work with anything). Cost of a Raspberry Pi 5 with 4GB of RAM: $60 + $10 of electricity per year.

And you can host multiple sites.

Yes, you can have power outages and internet outages, but for every problem there's a solution:
\- A UPS battery where you plug in your internet box and Raspberry Pi, and you're covered for a few hours
\- In France, my ISP Free offers a 4G backup for €5 per month that automatically takes over without specific configuration in case of an outage

And these two solutions are valid for general use, not just for self-hosting.

Fadogen works out of the box, but you're then free to configure it.

I like to imagine that Fadogen can become like what Shadcn is for UI components.

# What's next?

I'm just at the beginning of this project but I have tons of ideas:
\- Adding blue/green deployment to avoid interruptions between two deployments
\- Adding alternatives to Cloudflare like Tailscale
\- A registry of starter kits ready to use
\- Docker swarm compatibility
\- More frameworks supported
\- Allow deployment to VPS
\- k3s, k8s ?

On the technical side, I still need to write a lot of tests and documentation.

As the project is now open source, all contributions are welcome.

https://redd.it/1j83sj9
@r_php
Speeding Up Automated Tests

A common problem I see on mature Laravel projects is a slow pipeline, usually revolving around slow tests.

What sorts of performance frustrations have you guys had with your tests, and what are some tips and tricks you employ to combat slow tests?

I'm a big fan of fast feedback, and I feel like slow tests can really kill momentum. How slow is too slow for you, and what do you do to handle it?

https://redd.it/1j8ig97
@r_php
Is it just me or have running DB commands in Sail become really, really slow.

IDK if it's a Docker issue or a Sail issue, but I've had lag time recently when running migrations or seeding tables. This has been on two computers (up to date OSX and Linux Mint, respectively, both of which have been recently formatted), and persists even with fresh installs of Laravel 11 and 12. It seems that any time I run a sail command, it hangs for a good 10 seconds before executing.

In contrast, HTTP seems to load fine, as does connecting to the database via a GUI such as PHPStorm's database browser. It's just the CLI.

Anyone else have any similar issues?

https://redd.it/1j8okih
@r_php
Optimizing webpack encore output with Stimulus in Symfony

Hi everyone,

I've built a website using Symfony (formatcode.io) and used Stimulus for the JavaScript part. All third-party JS libraries are imported using lazy loading. However, despite this, the libraries still end up in the compiled JS files generated by Webpack Encore, making the imports quite large.

Do you know if there's a way to limit Webpack’s output strictly to sources used in Stimulus controllers? I’ve gone through the documentation but couldn’t find anything specifically addressing this issue.

Any insights or suggestions would be greatly appreciated!

Thanks!

https://redd.it/1j8ssys
@r_php
What Framework Should I Marry For The Next 5 Years?

Let me say upfront I don't know any frameworks at all, and I don't plan to ever get a job coding either. This is for me.

Current Contenders:
Code Igniter because benchmarks show good performance and it seems easy to use
Laravel because it's the industry standard and there's tons of tutorials, but it's intimidating me
Symfony because it seems modular enough to be lightweight, but it also seems hard and over complicated.

\-----

I'm building my second SaaS and, unlike last time where I rawdogged PHP into my own framework "accidentally", I want to actually be smart this time and use a real framework.

I want to follow MVC + business logic in services + custom helpers in their own neat little space. The site will have a API backend that sends JSON to be rendered server side for the frontend web app (no frontend framework, minimum JS) and also send the JSON straight to a native mobile app (android now, ios later).

The app (web and mobile) will let users post, see posts in a feed, vote on posts, have nice profiles, all the standard social community stuff. The web app is going to also have tools like landing page creators, a way to send newsletters to people who have followed your profile, and 244 other features I have planned over the next 5 years of ~~insanity~~ love.

If things take off, I will hire other devs and I don't want my backend framework to be so esoteric or uncommon that hiring will be difficult or extra expensive.


https://redd.it/1j8w7lm
@r_php
What are your go-to strategy when implementing internationalization/translatable entities?

Let's say you need to create a news website with articles that could be translated to multiple languages. What stack of libraries would you choose to implement that? I noticed that there are not many resources about translating entities. I know there is https://github.com/doctrine-extensions/DoctrineExtensions/blob/main/doc/translatable.md that is not supported by EasyAdmin, though (but I think I can think of few ways that it could be used with EasyAdmin regardless). docs also mention https://github.com/KnpLabs/DoctrineBehaviors, but it doesn't seem to be supported anymore. Would you use these existing libraries and abuse EasyAdmin to work with them somehow, would you roll out your own admin solution, or maybe a translation solution? What would be your strategy?

https://redd.it/1j914ix
@r_php
Why php doesn't resolve home directory

Hey. I just learned something new.


file_get_contents('~/file.txt') = false
file_get_contents('/home/file.txt') = _file.txt contents


What's weirder is

realpath('~/file.txt') = false
`realpath ~/file.txt` = /home/file.txt ( backtick is exec )


Anybody have any idea what's up? Working on some noscripting library and never noticed that before. Seems like a weird behaviour, but cannot find any bug reports / conversations about home path not being resolved. Don't see that also as a security issue really.



https://redd.it/1j94qmu
@r_php
I made a Blade starter kit

I made a Laravel Starter kit for Blade fans, it has everything the new official starter kits have, just built with good ‘ol Blade: https://github.com/imacrayon/blade-starter-kit

laravel new my-app --using=imacrayon/blade-starter-kit if you're feeling wild.

https://redd.it/1j99lwo
@r_php
Help finding companies developing products in PHP

I'm working on a project where I need to compile a list of \~5,000 companies that meet these criteria:

* They operate in the USA, UK, Canada, or Australia
* They actively develop products using PHP
* They are currently in business

My initial approach was scraping LinkedIn, Indeed, and other job boards, assuming that companies hiring PHP engineers likely have active PHP-based products. But scraping is a bit too much effort for my needs.

Does anyone know of a better approach—whether free or paid—to gather this kind of data? Any tools, datasets, or directories that could help?

https://redd.it/1j9fsh9
@r_php
I made a composer package that uses GPT 4o Mini to write documentation for your Laravel app! It's super cheap cost wise, customisable and skips any generated files allowing top-ups after new files are added! Let me know your feedback <3
https://github.com/genericmilk/docudoodle

https://redd.it/1j9jpje
@r_php
Pleasently suprised with DataGrip - should I try phpstorm again?

I have been a vim user for many years. I program in vim or emacs.

In an effort to find a SQL "ide", and after trying all of them, I was really impressed with DataGrip. In the past, I didn't like full IDEs because it was "so much going on" when compared to my blank vim screen.

But DataGrip has many features to reduce clutter and noice. I like it.

Maybe I should take another crack at phpstorm. Especially cos the vim emulation is very well done.

Any one moved from vim and stayed?

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