PHP Reddit – Telegram
PHP Reddit
34 subscribers
292 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
Decent DX with Slim/Twig/Alpinejs

I've been testing out Alpinejs quite a while. Was working on a side project in golang with sqlite and Alpinejs, but had a priority shift, as something came up over this weekend.

A 2nd degree friend of mine got in touch with me, requesting some internal tooling to manage his WhatsApp logistics. After carefully analyzing his conversation, and saw that this was mainly his side hustle, and had no intentions in scaling up due it's nature, I've decided to help him out, ofc $$$ is involved.

The tech stack was simple:
PHP 8.4
Slim
Twig
raw dogging PDO + sqlite
JS libs: Alpine, Tiptap, Hammer and Chart (all CDN btw)
Bulma, wasn't even bothered to waste time with styling. Just mainly focused for mobile styling.

Feels actually fresh to write PHP again, ofc I forgot to mention that I did include additional libraries for sanitization. Have 3 layouts (auth, dashboard and homepage) to properly load the necessary noscripts on each page.

I've managed to work on a 80% crud operations, with chartjs + half ass working PDF within a single day.

And consider i haven't touch for nearly 2 years. If I was to write the same thing in Laravel or Symphony, would have taken me 4 to 5 days just a MVP.

Oh, I was also a bad boy. Wrote +20 route with the logic in a single file. There are only 2 middlewares: throttle and csrf. The entire logic is around 1.8k lines of code.

tldr; know your foundation and everything else is easy.

https://redd.it/1jntxmp
@r_php
Easily create product webpages in your website Video preview

https://reddit.com/link/1jnvpvt/video/ybt1qgffjyre1/player

Sharing a video preview of creating a product from admin panel and displaying in the website. Using Laravel and Livewire.

Project:

https://github.com/oitcode/samarium

https://redd.it/1jnvpvt
@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/1jnwilu
@r_php
Anyone else regret using Livewire?

I'm building a project for a friend's startup idea, and I chose to use Livewire. I thought it was a great idea to have both the frontend and backend in the same language, meaning that my friend's other friend who is also working on the project wouldn't have to learn 2 new frameworks.

However, I'm starting to regret my decision. These are the reasons why.

Poor Documentation and Lack of Community

Despite the fact that it is developed by Laravel, there doesn't seem to be much of a community around Livewire. The documentation is also pretty poor, particularly when it comes to Volt. I installed Breeze with Livewire, and the Livewire installer created Volt class-based components. I thought this was a pretty great idea - it seemed like React but in PHP. However, there is even less documentation for Volt than the rest of Livewire - it's relegated to a single page down the bottom of the documentation menu. And even then, the majority of the documentation is regarding functional components, not class-based components. (I personally think they should do the same thing that Vue 3 did with Options/Composition API - have a switch at the top of the documentation index that lets you choose which you want to see).

Unhelpful error messages

Often, when you encounter an error, you will get the following message:
htmlspecialchars(): Argument 1 ($string) must be of type string, stdClass given

To get the real error message, you're then required to look in the logs.

Lack of UI Libraries

Livewire does ship with a UI library (Flux), but it's a paid product. There are only a few other UI libraries specifically for Livewire, such as Mary UI.

On the whole, I think Livewire is a great idea but hasn't really taken off or been managed that well. I'm seriously considering ripping it out (at least for the core business logic of the site) and replacing it with Inertia and Vue (which I am much more familiar with).


https://redd.it/1jnx27n
@r_php
Weekly Ask Anything Thread

Feel free to ask any questions you think may not warrant a post. Asking for help here is also fine.

https://redd.it/1jntxdp
@r_php
Should I Master Pure PHP Before Becoming a Laravel Expert?

To become a master of Laravel, do I need to be really proficient in pure PHP first? I already have programming skills, understand OOP, and know PHP syntax along with common functions. I also built my graduation project using Laravel. However, I don't have a deep understanding of Laravel yet. I have never built a complete system with pure PHP, nor have I manually implemented models like MVC from scratch.

I want to gain deep understanding to optimize performance and enhance security as well. So, should I develop a complete system using pure PHP first?

https://redd.it/1jnu1yn
@r_php
How do you handle client requested data changes?

Lets say you deployed an app for a client.

Now the client comes back to you and requests some data to be changed, like wording in a table column. Or maybe changing the parent\\child of some data...

1. Create migration to change the data
2. Edit manually in SQL tooling
3. Create a custom endpoint that applies it in code
4. ...?

What's best practice here?

(To be clear, not database structure changes)

https://redd.it/1jo2wek
@r_php
Is route:cache enough for mostly-static websites?

I'm working on a small e-commerce website that sells 7 products in total. Which gets the products from the database. And the data doesn't change often (if at all).

So, what kind of caching method would you recommend for this? Do I use something like Cache::rememberforever and re-set the cache when model changes? Or would php artisan route:cache command be enough for this purpose?

https://redd.it/1joc2ju
@r_php
Improving at Legacy Code

I don't know if this is the right place to ask this, but I've come to the conclusion that (entirely unintentionally) my career has made me specialise in Legacy code over the last few years.

However, I've been wondering what the best way is for me to get "better" at dealing with legacy code. I think it would be a nice skill to have on my CV if/when I move on to a new job, and likely something that will never be entirely useless. So far it's been mostly by accident but I wonder where I would go from here if I were more intentional about it.


(Apologies if this qualifies as "asking for help", I intend it mostly as a discussion and to hear from others in a similar position.)

https://redd.it/1jodq69
@r_php
PHP-FPM with latest news from 2011
https://php-fpm.org/

https://redd.it/1joe1fq
@r_php
Vote: Facades, helpers, or pure DI?

\\"Pure\\" DI

Helper functions

Facade

What is your preferred way of doing it?

Please, elaborate.

https://redd.it/1jogk9u
@r_php
PHP Crash Course by Matt Smith

I've been meaning to learn PHP for a while now, but life got in the way. I remember Jon Duckett, Program with Gio, and Laracasts as being much recommended sources to learn from. However, I also noticed a book that came out very recently: PHP Crash Course by Matt Smith. I like that it's recent and that it provides exercises with each chapter.

Does anyone here have experience with this book? Or does it seem like it focuses on the right subjects? There's a nice sample to look through at the link above.

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