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
Avoid Using SQLite in Development Unless It's Also Used in Production

Using SQLite as the dev database is a trend in the Laravel community nowadays. On the other hand, SQLite was promoted as the default database in the framework. But I’ve experienced unexpected issues with this practice, and I don't want others to face the same.

It might be fine if you only use query builder methods, but even then, there are issues. For instance, if you're familiar with FULLTEXT indexes in MySQL and try to use them in a SQLite dev database, you'll get an error since SQLite doesn't support them. You'll have to take some additional steps like following.

// migrations
if (in_array(DB::connection()->getName(), ['mariadb', 'mysql', 'pgsql'])) {
$table->fullText(['noscript', 'text']);
}

// controllers
if (in_array(DB::connection()->getName(), ['mariadb', 'mysql', 'pgsql'])) {
return $this->builder->whereFullText(['noscript', 'review'], $this->value);
}

If you are developing a large-scale project, you can't limit yourself to using only the query builder especially when you have dashboards. Recently, we shipped a project(uses MySQL in production and SQLite in dev) to production. This was a project with a very limited time frame, so we didn't have much time to plan properly. In fact we rushed to development. Everything worked as expected in the development environment and all tests passed. But then, our clients started reporting server errors. We had to spend a considerable amount of time and effort debugging it since it was so unexpected. At first, we thought it was an issue with our server, but eventually, we found the culprit in the following line.

$query->selectRaw(
"SUM(amount) as amount,
SUM(CASE WHEN type = ? THEN amount END) as infinite,
SUM(CASE WHEN type = ? THEN amount END) as recurring,
strftime('%Y-%m', subscribed_at) AS interval",
[SubnoscriptionType::Infinite->value, SubnoscriptionType::Recurring->value]
);

Can you spot the issue? Don’t worry if you can’t, most of us aren’t DB experts. It was `strftime('%Y-%m', subscribed_at) AS interval`. MySQL doesn’t have a `strftime` function, so we had to change it to MySQL equivalent `DATE_FORMAT(subscribed_at, '%Y-%b') AS \`interval\``.

So the final MySQL equivalent is:

$query->selectRaw(
"SUM(amount) as amount,
SUM(CASE WHEN type = ? THEN amount END) as infinite,
SUM(CASE WHEN type = ? THEN amount END) as recurring,
DATE_FORMAT(subscribed_at, '%Y-%b') AS `interval`",
[SubnoscriptionType::Infinite->value, SubnoscriptionType::Recurring->value]
);

This is just one instance. There are many differences between MySQL and SQLite.

Conclusion: **Use a production database system in development environments**.

Finally we'd better use follow practice: **Use a production-equivalent environment as much as possible in development (not limited to the database)**.

I'd love to hear your thoughts.

https://redd.it/1jubxrg
@r_php
Right way to oop with php

Hi, I'm working as a full stack php developer. My job mainly requires procedural style php code. So I'm quite well versed with it.

Now, I have been trying to learn php oop. But no matter how many videos or guides i see, its still confusing.

Main confusion comes from
1. File organization
- should each class be a seperate php file
- should utility class ( sanitization, uppercase, lowercase etc) be all combined in one?
- how to use one class in another class

2. How to create class
- what should constitute a class. Should user be a class defining creation / deletion / modification of users
- what exactly should a constructor of class do ( practically)

I'm still trying to defer mvc architecture for now. In order to understand how the design and flow for oop program should be done

Any and all help with this is helpful. I understand the basics, but having difficulty with irl implementation. Please recommend any guide that helps with implementation rather than basics.

Thanks

https://redd.it/1judmcu
@r_php
PHP learning tips for job interview

Hey all, I hope it's okay that I ask this here. Sorry if not :(
I had a job interview last week which went well. Now they want a second meeting with one of their programmers and we will look at some code.
I'm very nervous because I think that I'm not good enough yet.
I have 1 to 1,5 years "experience" in PHP but mainly with Laravel which makes a lot of things pretty easy.
For example I used Laravel Breeze, so Login implementation was always easy and I never learned stuff like this in plain PHP ( never wrote something from scratch ). I still forget a lot of stuff like how to validate requests properly (is this normal?).
I fear that my general PHP knowledge isn't good enough.
I have 2 days left. Do you have recommendations for learning material? On what should I concentrate? Maybe coding principles in general?
What would you expect of a junior full stack developer?
I know you can't know exactly what they want me to do (I don't know either) but any advice would be much appreciated.


https://redd.it/1jurvqm
@r_php
Samarium v0.9.5 - Improvements and fixes (Search implemented, npm issues fixed, more DB seeding, more blade components, UI updates)

Hello All,

Made some improvements and fixes during mid March to now to the Laravel and Livewire based project I have been developing. Wanted to share version 0.9.5 with you all.

It is a billing/finance tracking application with ERP like features.

https://github.com/oitcode/samarium

|Area|Improvements|
|:-|:-|
|Search|Basic search implemented for product, sale invoice, customer, vendor, webpages, posts. |
|npm security warning fixes|Updated npm packages so many security warnings during npm install are fixed.|
|Blade components|More blade components. Easier to update all at once now. Still need to create more components.|
|Test Code|Added more test code.|
|Database seeding|There were some issues with the database seeding. It is fixed now.|
|Product display UI updates|UI is update for product display in both admin panel and the website.|
|Misc updates|Sale invoice create minor bug fix, misc updates.|

Dashboard with changed colors



It is a work in progress, but still sharing the update here.

Feedback, comments and/or contributions are highly appreciated.

Thanks.

https://redd.it/1jv00m7
@r_php
Anyone using HTMx on your PHP project?

I applied HTMx to my WordPress project (PHP). When a user clicks an item on the image, the details of the Item show instantly. I like HTMx! https://setupflex.com/

Who else is using HTMx in their project?

https://redd.it/1jv5ldf
@r_php
Symfony developers in brasil

Aqui da comunidade quem é do brasil?

Who here in the community is from Brazil?

https://redd.it/1jvb5w6
@r_php
Time to make a basic program in PHP for WordPress

Hello. I wish to make a basic program in PHP that takes product attributes and can make Woo commerce combos based on product attributes. I wish to have this be my first program even though there maybe another on the market.

So how long to learn PHP coding to do a simple program such as this one?

https://redd.it/1jvinui
@r_php
After All This Time, ChatGPT Still Blows My Mind and Sometimes Freaks Me Out (context in comments)
https://redd.it/1jvw56m
@r_php
PHP RFC: Change default value for zend.exception_ignore_args
https://wiki.php.net/rfc/exception_ignore_args_default_value

https://redd.it/1jvxadr
@r_php
Please review my new bundle, RICH, for building robust applications in Symfony

I've been using Symfony since 2012, and last year, I needed to build a new application that had both web and REST API components.

I was familiar with hexagonal architecture, domain driven design, CQRS, and event sourcing, but they all seemed overly complicated. I also knew about API Platform, but it seemed like overkill for basic REST APIs. Plus, I needed my application to support standard HTML web views and JSON API responses.

Through a lot of experimentation, I came up with a similar but simpler architecture I've named RICH: Request, Input, Command, Handler.

A request (from anywhere) is mapped onto an input object, once validated, the input object creates a command object, which is passed (either manually or via message queue) to a handler object which performs the actual business logic.

It's nothing groundbreaking, but I believe it's more flexible than the #[MapRequestPayload] attribute that comes bundled with Symfony, and allows you to build robust applications easily.

I've written a lot more in the README and would love your thoughts and feedback.

https://github.com/1tomany/rich-bundle

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