News for hackers. Stuff that matters.
Re:PHP in 2023 by impulser_ on Tuesday January 17, 2023 @07:13AM (#34411572)
If you are thinking about building a web application, take a look at Laravel. I not a huge PHP user, but Laravel is always on the top of my list for building web applications. It's the greatest web framework to ever exists, even better than Rails IMHO.

The ecosystem around Laravel is really incredible and unlike any other framework. They have libraries for every stage of a web application from taking payments all the way down to server management and hosting.

They even have awesome libraries like Inertia which are built for Laravel but can be used with other frameworks.

It's the only reason I still stay fresh on my PHP.

Re:PHP in 2023 by zeptonix on Tuesday January 17, 2023 @07:38AM (#34411734)
Just to offer an alternate opinion for anyone reading -- check out Next.js
Re:PHP in 2023 by clementai on Tuesday January 17, 2023 @08:13AM (#34411981)
Next.js is great but can't compare to Laravel, they are not for the same use case. Laravel comes with an ORM, a job queue, a mail framework... And it can also scaffold a complete auth system for you
Re:PHP in 2023 by machiaweliczny on Tuesday January 17, 2023 @12:50PM (#34415823)
You can just add Bull/Temporal, Prisma/Knex and Braze and you can swap stuff when needed but I understand that for new people it's nice to have everything integrated when starting out.

Still seems like most people write separate backend and Nest.js is most popular. I am not a biggest fan yet personally.

Re:PHP in 2023 by avaldez_ on Tuesday January 17, 2023 @08:20AM (#34412044)
How so? Nextjs only offers ssr and routing. Nothing else. Not even close to the full stack functionality you find in a default laravel or rails project.
Re:PHP in 2023 by leerob on Tuesday January 17, 2023 @09:00AM (#34412411)
It also has API routes and Middleware. But yeah, Laravel includes more by default. With Next.js, you need to pick a few more tools to go along with your stack. E.g. Next.js, NextAuth, Prisma, SQL database. You end up in a similar place, it's just not all part of the same package. That may or may not be beneficial for your team.
Re:PHP in 2023 by brushfoot on Tuesday January 17, 2023 @12:48PM (#34415804)
And the advantage of Next is that you can leverage React components server side and client side, and share code between them.

Laravel Livewire is pretty nice for basic interactivity, which is all many sites need, but React becomes useful as soon as you start needing app-like features. At that point, using Next, which is already plugged in to that ecosystem, is a very nice experience.

Next is great for static sites, too, so nowadays I prefer putting my time into that vs. fragmenting between a more purely server-side framework like Laravel.

Re:PHP in 2023 by kyriakos on Tuesday January 17, 2023 @11:36PM (#34423487)
Inertiajs is the right solution if you need more interactivity than livewire. It can be used with react or vuejs out of the box (probably svelte too but haven't looked it up).
Re:PHP in 2023 by 0xblinq on Wednesday January 18, 2023 @03:24AM (#34424578)
Next.js is great as long as what you're building is not much more than a landing page, or you're proxying to a real backend system (by another team, etc).

Trying to build a "full stack" application with just Next.js is suiciding everyone that comes to the project after you leave.

Re:PHP in 2023 by code_runner on Tuesday January 17, 2023 @07:19AM (#34411611)
+1 for laravel as well. I joined a php project for a fresh rebuild in laravel and had mostly .net experience. Laravel was great.

The documentation is an almost perfect blend of examples and nitty gritty detail. The documentation is almost engaging if you’re coming from other frameworks.

I found myself thinking “wow that’s almost no code, what about this feature or that” and the next section would be the exact topic I was wondering about. Had a blast and could learn more php details as I went

Re:PHP in 2023 by spiderfarmer on Tuesday January 17, 2023 @08:14AM (#34411996)
This is exactly what I told my friends the other day. The writers of the documentation do a terrific job placing themselves in your shoes.
Re:PHP in 2023 by calvinmorrison on Tuesday January 17, 2023 @08:08AM (#34411940)
Were building some internal tools for customer service on Laravel's Orchid package and its the first truly RAD I've had in php that doesn't hold me back. Building interfaces is a pain and I lost touch with Javascript a decade ago, but it handles all of that for you.

Highly recommend

Re:PHP in 2023 by spiderfarmer on Tuesday January 17, 2023 @08:08AM (#34411942)
I'm rebuilding an old online community / forum in the TALL stack. It's awesome. I do have to do a lot of raw sql query building to keep it performant though.
Re:PHP in 2023 by BuckyBeaver on Tuesday January 17, 2023 @08:17AM (#34412019)
So do you just not use Laravel’s ORM?
Re:PHP in 2023 by stef25 on Tuesday January 17, 2023 @08:37AM (#34412199)
It's possible to combine query builder, orm and raw sql any way you want
Re:PHP in 2023 by spiderfarmer on Tuesday January 17, 2023 @08:23AM (#34412066)
I do use it, but for some of the more complex queries I use the Raw SQL part of it.
Re:PHP in 2023 by BuckyBeaver on Tuesday January 17, 2023 @08:28AM (#34412116)
OK, good to know that you can do both.
Re:PHP in 2023 by francislavoie on Tuesday January 17, 2023 @12:20PM (#34415370)
It has a full-fledged query builder: https://laravel.com/docs/9.x/queries
Re:PHP in 2023 by waffl on Tuesday January 17, 2023 @08:12AM (#34411967)
Also inertia.js just reached 1.0 and has been really fantastic to work with.
Re:PHP in 2023 by tasuki on Tuesday January 17, 2023 @08:12AM (#34411970)
> [Laravel]'s the greatest web framework to ever exists

Back when I worked with PHP, we used Symfony and several coworkers very much looked down on Laravel. Symfony was modular and you could easily switch whichever component for your own by just implementing the interface and overriding the dependency injection thing. Word was that Laravel hardcoded many things and was less customisable.

What is your take on this? In what way is Laravel superior to Symfony?

Re:PHP in 2023 by dpcx on Tuesday January 17, 2023 @08:36AM (#34412189)
I think that people believe they'll switch out components more than they really end up doing, but in Laravel, you can override things within Service Providers, and then use the built-in dependency injection to get the thing you want.
Re:PHP in 2023 by iillexial on Tuesday January 17, 2023 @08:28AM (#34412112)
Laravel is great for prototyping and fast building. If you want to make a big application with Laravel, it's better to use Symfony-like approach with interfaces and DI (you can do it by using Laravel). What I personally do not like in Laravel is their ORM, too much magic calls involved.
Re:PHP in 2023 by kugelblitz on Tuesday January 17, 2023 @08:44AM (#34412261)
Yes, the magic involved in Eloquent ORM, also the central use of Facades or that the models are based on migrations (which uses code comments as a crutch for auto-completion), instead of the migrations being based on the models (how Symfony uses simple PHP objects, from which then Doctrine generates the "missing" migrations).

I can live with both frameworks, but Symfony just feels cleaner and more transparent in its workings without using magic to make things look simpler.

Re:PHP in 2023 by kugelblitz on Tuesday January 17, 2023 @08:30AM (#34412131)
This is the big reason I use Symfony for most of my projects.

I do lots of refactoring and modernizing of legacy or non-scalable codebases as a freelancer; with Symfony you can replace it module by module and slowly implement the Symfony framework structure.

Through some configs, it can do dependency injection, event listener stuff, etc, but the framework is mostly glue around components.

With Laravel, you need to go "all-in", and you had to do things the Laravel way. If I strayed from that path, it would make things really difficult.

I still work on projects with either of the frameworks, but if I had a choice, it would almost always be Symfony.

Re:PHP in 2023 by BuckyBeaver on Tuesday January 17, 2023 @08:13AM (#34411985)
Looking at the Laravel site, I’m concerned about Laravel’s reliance on an ORM. Not only because ORMs are widely derided, but because I have a legacy MySQL DB and PHP 5 project I want to resurrect. I’m down to rewrite the server, but how do I restore a database full of user data with Laravel?
Re:PHP in 2023 by jt2190 on Tuesday January 17, 2023 @08:29AM (#34412126)
Laravel is “linked” together via a combination of Composer dependency manager and Dependency Injection. You can easily customize your setup to remove the dependency on Eloquent ORM and use something else.
Re:PHP in 2023 by BuckyBeaver on Tuesday January 17, 2023 @08:33AM (#34412163)
Thanks!
Re:PHP in 2023 by spiderfarmer on Tuesday January 17, 2023 @08:17AM (#34412016)
What I'm doing is recreate everything the Laravel way and worry about importing the data (millions of pictures, videos and comments) later. I figured that once I'm proficient at Laravel that writing some import jobs would be relatively easy.
Re:PHP in 2023 by BuckyBeaver on Tuesday January 17, 2023 @08:19AM (#34412034)
Thanks! That’s happens to be just what I need to do: import pictures and related data.
Re:PHP in 2023 by cellover on Tuesday January 17, 2023 @08:24AM (#34412076)
Does your DB have a classic design? You can very easily map an existing DB with a fresh Laravel install, just write a couple Models, their relationships and you're almost set.

I have been working with Laravel on a daily basis since 6 years and have never felt more efficient with code.

Re:PHP in 2023 by BuckyBeaver on Tuesday January 17, 2023 @08:32AM (#34412153)
Not sure what you mean by classic, but I designed it manually to be queried with plain SQL. So I suspect the answer to your question is yes.

Thanks for the info!

Re:PHP in 2023 by cellover on Tuesday January 17, 2023 @09:50AM (#34413019)
By classic I mean something somewhat standardized like user table: id, name, email ; post table: id, user_id, content etc.
Re:PHP in 2023 by BuckyBeaver on Tuesday January 17, 2023 @02:43PM (#34417637)
Pretty much, then, yes.
Re:PHP in 2023 by pocketsand on Tuesday January 17, 2023 @09:22AM (#34412662)
I work on a project like this and you'll run into some papercuts, but it's not hard.

You can take a model for anything in your legacy code, and just set properties on the model to teach Laravel how to deal with things that don't follow conventions.

For example, you can override the table name. Suppose you had a legacy table called "postdata". In Laravel, this table would be called posts, and a model would be Post.

So you'd just tell Post to query postdata rather than posts.

Likewise, you can tell it which fields to cast as dates, booleans, etc. You can tell it which fields represent timestamps for updating, creating, deleting and so forth.

You can setup relations that don't follow naming conventions the same way.

The only issue I've run into is doing things like setting up relationships across databases. You can do it, it's just not super straightforward.

I think you'll find it's a breath of fresh air to have a modern wrapper around your legacy code, and that your legacy stuff will then fit in quite nicely with your new work.

Re:PHP in 2023 by BuckyBeaver on Tuesday January 17, 2023 @02:41PM (#34417596)
Great, thanks! I’m pretty psyched to get started, after reading these comments.
Re:PHP in 2023 by martin_drapeau on Tuesday January 17, 2023 @08:43AM (#34412249)
+1 Laravel. Built-in queues is a killer feature that makes your Web App scale with little pain.
Re:PHP in 2023 by bakugo on Tuesday January 17, 2023 @09:10AM (#34412527)
Laravel is great if you just want to get something simple done as fast as possible with the simplest, most elegant (at a glance) code possible and don't care at all about understanding how it works, what's going on under the hood, performance, doing anything the devs didn't expect, etc.

Everything in Laravel is as obscured, "magical" and opinionated as possible for the sake of making the code "beautiful" (again, at a glance) to the detriment of basically everything else. I really have no idea how any experienced programmer can look at it and think it's usable for anything beyond the most simple project.

The mere fact that models are PHP classes but none of their properties that exist in the database are actually declared as properties in the class because the ORM just "magically" puts them there at runtime should be enough to drive away any sane person. And let's not forget the amazing "Facades" a.k.a. glorified global variables filled with magic methods that you're expected to make extensive use of.

Re:PHP in 2023 by ceejayoz on Tuesday January 17, 2023 @09:40AM (#34412868)
> And let's not forget the amazing "Facades" a.k.a. glorified global variables filled with magic methods that you're expected to make extensive use of.

Each of the facades comes with a corresponding dependency injection if you prefer. You can write an entire Laravel app without ever touching a facade.

Re:PHP in 2023 by pocketsand on Tuesday January 17, 2023 @09:28AM (#34412735)
Can you give me a few real life examples where you got bit by the "magic" conventions or ran into any serious issue from not explicitly setting properties on your models?

Facades are not global glorified variables with magic methods. Usually they're just a way to instantiate and access a class with less code. People complain that facades limit testability. In fact, they're easily mocked. Etc.

The docs do a very good job of explaining how things work and how you can override any "magic" you may not like. If something is doing something you didn't expect, you probably didn't read the docs. In fact, a delight of working with Laravel is it's so intuitive that you can often guess how to achieve something and be right.

Have you worked with Laravel in practice?

Re:PHP in 2023 by bakugo on Tuesday January 17, 2023 @10:18AM (#34413404)
> Can you give me a few real life examples where you got bit by the "magic" conventions or ran into any serious issue from not explicitly setting properties on your models?

I shouldn't need "real life examples" to explain why using objects with magic dynamic properties instead of declaring the properties on the class is stupid. If I can't look at a model class and know what properties and methods it has, why is it even a class? With all the improvements made to PHP in the past decade, it feels like going back to the days when I was just using associative arrays to represent database objects.

> Have you worked with Laravel in practice?

Yes, I tried using it, was immediately put off by the issues I've described, then tried Symfony and never looked back. For every piece of dumb nonsensical magic Laravel does, you can look at Symfony to see how it should be done properly.

Re:PHP in 2023 by pocketsand on Tuesday January 17, 2023 @11:20AM (#34414403)
You can look at a Laravel (Eloquent) model and easily see what methods it has. Nothing is hidden -- at least no more than any ORM that inherits from another class which gives it functionality.

As for properties -- yes, they're not explicitly described but mapped to the database schema. Other ORMs, like that in Ruby on Rails, also do not explicitly set model properties and just map to database columns. People have been upset about this forever, but everyone else has happily used Active Record and had no major issues, all while enjoying not having to add a dozen lines of code to annotate props.

In both Rails and Laravel you can define accessors and setters, either overwriting the magic property for the column or defining new properties.

If not seeing the properties on the model is a huge problem, there are plugins to generate them and put them in the model. My IDE gives me direct insight by inspecting the table.

I'm happy not to have to write out all the props twice when there's no tangible performance issue and I've never had any other problems with dynamically getting the model attributes from the schema.

You're taking a matter of taste and context-based tradeoffs and acting like those reflect unchallengeable principles.

Symfony is a great piece of software. So is Laravel. Github numbers alone will show you how compelling so many developers find Laravel. Of course, there will be haters who think they're all stupid, uneducated, bad, idiotic, lazy, etc.

Everyone makes trade-offs based upon taste or prior decisions. Consider Django. There, you explicitly define properties, but link them to the type of database column they'll use. Then, you can generate a migration based upon the model, and then run that migration. I really like that pattern. Removes tedium of writing migrations, preserves ability to modify the migrations, and makes things explicit.

When I used SQL Alchemy in Python, it completely allowed me to not write migrations, only models. That was very nice, until it wasn't. But then I just had to do a few things manually -- a reasonable price to pay for saving a bunch of time in the other 19/20 of cases.

These are all just different ways of getting to the same place. Each has benefits, each has drawbacks, the extent of each which will depend on the project and the developers' tastes.

Re:PHP in 2023 by ceejayoz on Tuesday January 17, 2023 @11:36AM (#34414663)
> Symfony is a great piece of software. So is Laravel.

And to be clear, Laravel is a piece of Symfony software, and a good example of what you can do with Symfony packages and a bit of opinion.

There are 13 Symfony dependencies in https://github.com/laravel/framework/blob/9.x/composer.json alone, and many of the Laravel packages listed in there also depend on them; the Laravel Request class extends Symfony\Component\HttpFoundation\Request, the Response class extends Symfony\Component\HttpFoundation\Response, etc.

Re:PHP in 2023 by francislavoie on Tuesday January 17, 2023 @12:27PM (#34415478)
It's a lot more than "a bit of opinion". It's a huge framework with tons of unique and original features. You're being very reductive. Yes it does use Symfony components for some core functionality, but that's just a small part of what Laravel offers.
Re:PHP in 2023 by ceejayoz on Tuesday January 17, 2023 @12:34PM (#34415577)
I think we largely agree; I just think "Laravel or Symfony" is somewhat a false dilemma because of this. You can build your own system on Symfony libraries... or you can use Laravel's system that's heavily built on Symfony libraries, with a lot of the plumbing done for you.
Re:PHP in 2023 by pocketsand on Tuesday January 17, 2023 @02:01PM (#34417051)
Technology companies routinely use/license technology from other companies in their products. If, for example, Apple relies upon Samsung for displays and memory in their laptops, it does not follow that you're actually buying a Samsung laptop.

In any event, Laravel has never been shy about its debt to Symfony.

Re:PHP in 2023 by bakugo on Tuesday January 17, 2023 @01:53PM (#34416918)
The only benefit you've mentioned is writing less code. Which just proves my original point about Laravel being for people who want to get things done as fast as possible with the minimum effort possible, regardless of how much sense it makes.

>Consider Django. There, you explicitly define properties, but link them to the type of database column they'll use. Then, you can generate a migration based upon the model, and then run that migration. I really like that pattern. Removes tedium of writing migrations, preserves ability to modify the migrations, and makes things explicit.

This is exactly what Symfony with Doctrine does, and it's the correct way to do it. The benefits vastly outweigh the "drawback" of having to write slightly more code.

Re:PHP in 2023 by pocketsand on Tuesday January 17, 2023 @02:11PM (#34417188)
When I work in Django, instead of other frameworks I use, I think "I like this more, I like this less; this works better for me in these circumstances, this does not." But I've never felt it made any sense at all to pronounce one as objectively better than another.

In most cases, it is a matter of taste and tradeoffs that vary based upon circumstance.

You can keep saying "this is the correct way" with all the conviction in the world, but it won't turn matters of opinion and circumstance into universal fact.

Re:PHP in 2023 by Seb-C on Wednesday January 18, 2023 @03:43AM (#34424709)
It's not a matter of personal opinion, it's a fact that the data mapper pattern (like doctrine) allows for a better and more maintainable architecture than active record.

Separating the data access layer, the models and the business logic (basically a 3-tier architecture) is a widely used and proven industry standard to keep a sane, maintainable and testable codebase.

Active record ORMs like Eloquent mixes everything in a single layer (business logic in the model events, data accesses are done by the models), but as soon as you reach a significant level of complexity, it is unmaintainable.

Even Laravel codebases that grow in complexity often ends-up wrapping Eloquent in a repository layer.

Re:PHP in 2023 by 0xblinq on Wednesday January 18, 2023 @02:58AM (#34424436)
So I suppose you also write your own compiler, your own operating system, and built its computer from bare transistors as well? Because all of that looks like magic to me too.

At some point you have to accept the foundation you have as something that works, it's battle proven, and it's built by experienced and reliable developers and you build on top of the shoulders of giants. Reinventing everything from scratch so that you understand it makes you the only one that understands it.

There was a famous phrase by Arthur C. Clarke that I think applies here along the lines of "Any sufficient advanced technology is indistinguishable from magic".

Re:PHP in 2023 by dgb23 on Tuesday January 17, 2023 @09:46AM (#34412952)
Laravel is a decent web framework, that comes with batteries included and _often_ has sensible ways to override and avoid things if you don't want them.

For example, you don't need to use the ORM at all and can just use their query builder (which is pretty good). It's there if you want it, but the framework works happily without it and doesn't get in your way in that regard.

I inherited a Laravel codebase from a previous contractor and it was reasonably ergonomic to navigate and extend, because I was able to lean on the framework documentation to understand how it all worked. But there were several points where it was _not_ reasonable, because of Laravel/PHP magic and those were pretty painful to figure out and debug.

The reason I wouldn't choose it myself anymore is the magic, the little surprises and hard to debug idiosyncrasies that it provides in order to look pretty. Also generally Laravel, PHP and related ecosystems are moving too fast and are difficult to keep up to date without breaking and/or misunderstanding things. It's not quite JS/npm level of churn, but unnecessary regardless. A more minor point is the baseline performance tends to be on the lower end of what I need.

There are ecosystems out there that value stability and clarity more and provide better tools to test and debug the code if necessary, and I've come to appreciate those things much more with experience than other factors such as reducing the initial development time.

Re:PHP in 2023 by chris1993 on Tuesday January 17, 2023 @08:56PM (#34422457)
What are your preferred alternatives to Laravel?
Re:PHP in 2023 by dreadnip on Wednesday January 18, 2023 @11:41AM (#34429058)
Symfony is more explicit, configurable and has way less magic.
Re:PHP in 2023 by 0xblinq on Wednesday January 18, 2023 @02:52AM (#34424404)
What other ecosystems and frameworks are you talking about? I've tried many things across many ecosystems in the last 20+ years and so far, despite any drawbacks it could have Laravel is the best one by a long shot. So I'm curious what those other better solutions you mention are and what are its trade offs.
Re:PHP in 2023 by hk1337 on Tuesday January 17, 2023 @10:05AM (#34413244)
> even better than Rails IMHO.

I don't know about that. I have been looking at Rails 7 and there's a lot things in Rails now I like better than Laravel.

Symfony did most of the heavy lifting with getting PHP relevant again, Laravel was just better at marketing. Laravel is good, don't get me wrong but everyone seems to think Laravel is the only good thing in PHP and a lot of Laravel is built with Symfony libraries.

Re:PHP in 2023 by okeuro49 on Tuesday January 17, 2023 @10:30AM (#34413616)
> If you are thinking about building a web application, take a look at Laravel.

Take a look at Symfony before Laravel. It will be very similar to Java developers who are familiar with Spring.

Re:PHP in 2023 by kakuri on Tuesday January 17, 2023 @11:18AM (#34414370)
I spent a week learning Laravel and modern PHP for a project that never materialized. I am so grateful the project never materialized, because for all the past 2 decades of improvement PHP remains a language I never want to work with. There may be some details in "A Fractal of Bad Design" that no longer apply, but the phrase itself still very much applies - PHP (and Laravel) remain a fractal of bad design.
Re:PHP in 2023 by ofrzeta on Wednesday January 18, 2023 @01:37AM (#34424014)
- Laravel has many "admin libraries" (Voyager, Orchid, Filament, Twill), some of them open core, each with their own ideosyncrasies. Symfony has EasyAdmin.

- Laravel uses Inertia for Vue.js or React integration while Symfony has an integrated solution with Symfony UX

- Symfony has become more modular with Symfony Flex

- Symfony has put a lot of effort into improving "developer experience" in the Symfony DX initiative

- Symfony has brillant docs in many languages including a new open book by Fabien Potencier and other Symfony collaborators