Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

martinbean's avatar

martinbean wrote a reply+100 XP

2d ago

Is it worth defining helper methods on models that traverse relationship chains?

@mikelmedina No. You shouldn’t be using helpers to “fix” bad code. You should just be eager-loading the relationships you actually need for a request.

martinbean's avatar

martinbean wrote a reply+100 XP

2d ago

Can I code a web application from these cloud frameworks? Google AWS Microsoft

@june23 What do those “frameworks” have to do with an application? They’re just cloud providers. They have services that you would deploy and run code on. Yes, you can use. You can also create and host a web application without them.

Your question is basically: “Can I make a journey with these vehicles? Car, van, truck.”

You need to get out of this rut of, “if I use X then I will be a proper developer”. You should be using things when it makes sense to use them; not as a box-checking exercise.

martinbean's avatar

martinbean wrote a reply+100 XP

5d ago

Laracasts website figma design?

@shivamyadav Which video? And why can’t you take inspiration from what you’ve seen? Why do you need the raw Figma file?

martinbean's avatar

martinbean wrote a reply+100 XP

5d ago

Key Requirements for Enterprise Mobile Applications

@ramnarayanank Do you actually have a question? Or did you just feel like posting LLM-generated spam today?

martinbean's avatar

martinbean wrote a reply+100 XP

5d ago

Laravel new with older version ?

@gpapamichelakis Why? You should always be using the most recent version of software.

martinbean's avatar

martinbean wrote a reply+100 XP

5d ago

If I create a CRM and I needed web developers to work on the CRM, would web devs not work on it if it was not successful?

@digitalartisan So what about “engineers“ that have worked on projects where a load of money has been sunk into it, and the project’s then failed or just been canned? Such as Metaverse, Apple Car, Windows Phone, etc?

martinbean's avatar

martinbean wrote a reply+100 XP

6d ago

Any way to pass the browser's session storage data to the middleware?

@shivamyadav No. That data lives in the browser. It’s client-side.

If any website could just automatically gobble browser session storage then that would be a massive security risk and attack vector.

You need to come up with a different method to achieve what you’re trying to achieve.

martinbean's avatar

martinbean wrote a reply+100 XP

6d ago

If I create a CRM and I needed web developers to work on the CRM, would web devs not work on it if it was not successful?

@june92 A developer will work on anything if you pay them enough to make it worth their while.

martinbean's avatar

martinbean wrote a reply+100 XP

1w ago

Food for thought

@randy_johnson You could also just dispense with it all and put everything in a single index.php script.

martinbean's avatar

martinbean wrote a reply+100 XP

1w ago

martinbean's avatar

martinbean wrote a reply+100 XP

2w ago

Is Laracasts ever going to do PPP adjustment on membership prices? It's incredibly tough to afford in some countries.

@motinska94 Laracasts runs deals around Black Friday (November) each year. If you really want Laracasts access then I’d suggest saving and then purchasing when a subscription is heavily discounted.

martinbean's avatar

martinbean wrote a reply+100 XP

2w ago

I accidentally deleted a Controller. How to recover?

@adamnet Are you actually going to reply? And say why you weren’t using source control when you’ve been told by multiple people to do so for months now…? Or will you just come back in a couple of months’ time with a yet another new post on how you’ve lost work and want to know how to get it back?

martinbean's avatar

martinbean wrote a reply+100 XP

2w ago

Filament Widget that gets data from WooCommerce via API

@earmsby 403 is a Forbidden response. So if the code works for one store but not another, it sounds like whatever credentials you’re trying to use does not have the permissions to actually view resources for that store. So the issue is going to be there; not with your code.

martinbean's avatar

martinbean liked a comment+100 XP

2w ago

I accidentally deleted a Controller. How to recover?

Oh, you're right: thread.

@adamnet You keep making the same mistake and asking the same question. Either accept that you'll occasionally lose work, or start using version control. If you want to be a serious developer, learn version control.

martinbean's avatar

martinbean wrote a reply+100 XP

2w ago

I accidentally deleted a Controller. How to recover?

Oh, you're right: thread.

@jussimannisto I seldom forget things I’ve read or seen. It’s a blessing and a curse 😅

martinbean's avatar

martinbean liked a comment+100 XP

2w ago

Is it good having approximately 900 lines of a function?

Jesus christ!

If that's your senior engineer writing that code today, they need to be sacked, ASAP!

That's not code written by a senior! They might have been there a long time, but they are not a senior engineer.

martinbean's avatar

martinbean wrote a reply+100 XP

3w ago

I accidentally deleted a Controller. How to recover?

@adamnet This is what version control is for. And I’m sure you had been advised to use version control some time ago…?

martinbean's avatar

martinbean wrote a reply+100 XP

3w ago

is there already an good implentation of passkey's in laravel?

@jaeggid That Laracasts series is a bit redundant now that Passkeys are natively supported by Laravel via a first-party package.

martinbean's avatar

martinbean wrote a reply+100 XP

3w ago

Database Replication

@eskiesirius This is literally the definition of premature optimisation…

martinbean's avatar

martinbean wrote a reply+100 XP

3w ago

Event-Driven Architecture, do I need it?

Should I bite the nail and continue down this road since it will eventually lead to a better product

@randy_johnson “Better” according to who…?

Event-driven architecture is like any other paradigm: it can be implemented well and it can be implemented poorly. Just implementing an event-driven architecture won’t automatically and inherently make the end result “better”.

If this is an inventory system then all you need to do is record adjustments in a table. Insert a row each time you take stock, and each time stock leaves (i.e. is sold).

martinbean's avatar

martinbean wrote a reply+100 XP

4w ago

Laravel Website Suddenly Slow After Server Migration – Possible PPA Launchpad Issue with PHP 7.4

Given this behavior, I’m wondering if this could be related to the PPA Launchpad issue. Am I thinking in the right direction?

@khanareeb You need to profile requests instead of just guessing.

Profile a request and see where the most time is being spent. My guess is, if you have moved hosting, that you’re probably pointing to a remote database that’s connecting over the network instead of via a socket on the same machine, thus introducing latency. But again, just a guess. You need to profile to confirm the actual cause.

martinbean's avatar

martinbean wrote a reply+100 XP

4w ago

what folder structure patterns have you found most effective ?

@imrandevbd You seem to have again replied to a thread just rewording exactly what I’ve written?

martinbean's avatar

martinbean was awarded Best Answer+1000 XP

4w ago

what folder structure patterns have you found most effective ?

@shivamyadav I’ve worked on probably hundreds of Laravel projects over more than 10 years now, and at companies of all sizes (from SMEs to Fortune 500s). The projects that fell apart and became unmaintainable messes were the ones where developers decided to be “clever” and create their own folder structure, or do “modules”, “domains”, or whatever.

Seriously, stick to Laravel’s default directory structure:

  • Put interfaces in an app/Contracts directory, which follows the framework’s convention.
  • Use managers for things that can have multiple providers (i.e. payment gateways). Think how Laravel uses managers for components you interact with (cache, queue, etc) where the code doesn’t change if you swap providers (i.e. from Redis to database). Try to strive for the same in your application where you’re relying on interfaces and managers rather than a specific provider.
  • If you have different “areas” in your application, then you can sub-namespace controllers (i.e. App\Http\Controllers\Admin).
  • For interactions with third-party services, I create a dedicated namespace in an app/Services directory (i.e. App\Services\Mux). I then treat this folder as a package, so it may have its own Artisan commands, Eloquent models, controllers, routes, etc with a service provider to register those resources.

It Just Works™ and scales, and your Artisan make:* commands still work without having to install horrible “glue” packages. And with the rise in AI-assisted development, sticking to the default directory structure will only help that given that’s what LLMs will be trained on.

martinbean's avatar

martinbean wrote a reply+100 XP

4w ago

what folder structure patterns have you found most effective ?

@shivamyadav I’ve worked on probably hundreds of Laravel projects over more than 10 years now, and at companies of all sizes (from SMEs to Fortune 500s). The projects that fell apart and became unmaintainable messes were the ones where developers decided to be “clever” and create their own folder structure, or do “modules”, “domains”, or whatever.

Seriously, stick to Laravel’s default directory structure:

  • Put interfaces in an app/Contracts directory, which follows the framework’s convention.
  • Use managers for things that can have multiple providers (i.e. payment gateways). Think how Laravel uses managers for components you interact with (cache, queue, etc) where the code doesn’t change if you swap providers (i.e. from Redis to database). Try to strive for the same in your application where you’re relying on interfaces and managers rather than a specific provider.
  • If you have different “areas” in your application, then you can sub-namespace controllers (i.e. App\Http\Controllers\Admin).
  • For interactions with third-party services, I create a dedicated namespace in an app/Services directory (i.e. App\Services\Mux). I then treat this folder as a package, so it may have its own Artisan commands, Eloquent models, controllers, routes, etc with a service provider to register those resources.

It Just Works™ and scales, and your Artisan make:* commands still work without having to install horrible “glue” packages. And with the rise in AI-assisted development, sticking to the default directory structure will only help that given that’s what LLMs will be trained on.

martinbean's avatar

martinbean wrote a reply+100 XP

4w ago

Football streaming

@gedirixin Thanks for signing up just to review and reply to a three year old thread…

martinbean's avatar

martinbean was awarded Best Answer+1000 XP

4w ago

How to obsfucate a Laravel application's code ?

@vincent15000 If you don’t want people to have your code, don’t give them it.

Any obfuscation can be easily defeated as PHP is an interpreted language. Any encrypted code needs to be decrypted before it can be ran, and obfuscated code is not going to hide anything of interest (such as API keys, database credentials, etc) if someone really wants to see them.

martinbean's avatar

martinbean wrote a reply+100 XP

4w ago

Plan subscription and Stripe

Are these plans differents products or the same product with different prices ?

@vincent15000 Only you can answer that.

  • Can I use swap and change plans? Then they should belong to the same product.
  • Do the different plans give access to different entitlements? That they should be separate products.
martinbean's avatar

martinbean was awarded Best Answer+1000 XP

4w ago

Use a policy with only the model id and avoiding N+1

Hmmm ... I wonder how I could use a policy with only a model id.

@vincent15000 That would be absolutely useless. If you call the gate using something like $this->can('update', 1); then how is Laravel supposed to know which model that 1 relates to? 🤷‍♂️

Stop over-thinking things and just use Laravel’s features as they’re documented.

martinbean's avatar

martinbean wrote a reply+100 XP

1mo ago

Increment/Decrement on High Traffic

@eskiesirius You shouldn’t be using a single column to hold the balance. You should instead of some form of ledger table, where you write individual increments and decrements as their own rows, and then derive the balance from the sum of those increments and decrements. It’s not “expensive” if you have a proper index in place.

martinbean's avatar

martinbean was awarded Best Answer+1000 XP

1mo ago

Prefix for session cookie

The application is served via HTTPS in production.

@vincent15000 So stop messing with the cookie prefix, and just set the appropriate configuration option: https://github.com/laravel/laravel/blob/a9fec26463bd62c220702c5d1e9f087c3ca67078/config/session.php#L161-L172

martinbean's avatar

martinbean wrote a reply+100 XP

1mo ago

No bootstrap.js file anymore in fresh laravel installations ?

@vincent15000 It became redundant when Laravel removed Axios from the the default installation, given all bootstrap.js did was import Axios: https://github.com/laravel/laravel/blob/12.x/resources/js/bootstrap.js

martinbean's avatar

martinbean wrote a reply+100 XP

1mo ago

Prefix for session cookie

The application is served via HTTPS in production.

@vincent15000 So stop messing with the cookie prefix, and just set the appropriate configuration option: https://github.com/laravel/laravel/blob/a9fec26463bd62c220702c5d1e9f087c3ca67078/config/session.php#L161-L172

martinbean's avatar

martinbean wrote a reply+100 XP

1mo ago

Prefix for session cookie

@vincent15000 But Laravel cookies are already secure by being HTTP only, optionally HTTPS-only, restricted to path, restricted to domain, and with cross-site restrictions. So what, exactly, “enhanced security” were you trying to add here?

martinbean's avatar

martinbean wrote a reply+100 XP

1mo ago

At what point do you stop patching CSS and just rebuild properly?

@muhammadali2003 This is why you don’t cut corners: “quick fixes” end up sticking around for much, much longer than intended, and the work to undo them becomes bigger than just doing things properly from the start.

I’ve not worked with WordPress for a few years now, but I’d start by extracting styles for components one-by-one into your theme.css file if you’re building an “old-style” theme. I can’t remember how styles work in block-based themes but again, just extract styles for one component at a time.

martinbean's avatar

martinbean wrote a reply+100 XP

1mo ago

Best approach for handling large file uploads and ZIP generation in Laravel?

@lailaih You need to look into multi-part/chunked uploading for large uploads. This is where the file is sent in multiple chunks (and requests), and then re-assembled server-side. It then means any failing chunks can be re-tried if they fail, and the entire upload paused and resumed.

martinbean's avatar

martinbean wrote a reply+100 XP

1mo ago

How to access a private folder (Storage app/private/documents) from another Laravel project

@adamnet It’s all going to depend on how the projects are hosted, and where the stored files actually live (i.e. on disk, or in some third party store like S3).

If the files are stored on disk, and both projects are hosted on the same server, then you could create a symbolic link so both applications can access the files. If the applications are stored on separate servers with separate file systems, then this obviously becomes much, much more difficult.

martinbean's avatar

martinbean wrote a reply+100 XP

1mo ago

How to access a private folder (Storage app/private/documents) from another Laravel project

@imranbru Wasn’t calling you a bot; just that you were giving OP answers copied from an LLM so it was like OP was chatting with a bot. It’s clear from your comments which ones are written by you (inconsistent formatting and grammar) and which one’s have been sourced from an LLM (suddenly perfect formatting and grammar).

If OP wanted answers from an LLM then they could ask Lary, or something like ChatGPT, themselves instead of waiting for you to do and then copy-and-paste the response.

martinbean's avatar

martinbean wrote a reply+100 XP

1mo ago

How to access a private folder (Storage app/private/documents) from another Laravel project

In project 1users will be able to only submit (post) pdf documents. […] In project 2 the administrators must be able to see all the pdf documents

@adamnet Why are these two different projects in the first place? They’re clearly the same project, just with users with different roles.

Also, @imranbru is just regurgitating an LLM response to you, so you’re essentially chatting with a bot.

martinbean's avatar

martinbean wrote a reply+100 XP

1mo ago

Doomscrolling During AI Wait Times is Killing My Focus — Anyone Else?

@shaungbhone The irony of posting an AI-generated post to complain that you can’t focus when using AI…

martinbean's avatar

martinbean wrote a reply+100 XP

1mo ago

Prefix for session cookie

@vincent15000 Why have you added that prefix?

martinbean's avatar

martinbean liked a comment+100 XP

1mo ago

Larabox: The Local Dev Stack Manager that I built.

I develop on a Mac. Tag line:

Escape the complexity of Docker and WSL. Larabox provides isolated, pre-bundled native binaries for Nginx, PHP, MariaDB, Node.js and more optimized for Windows and live in seconds. 

Pre-bundled native binaries...who is compiling these on or for Windows, there already native binaries.

Docker isn't complex, neither is WSL.

I am a bit old school, if you use Nginx or Apache, you should know how to install and configure them.

More optimized for windows, as to 'less optimized'? How...

martinbean's avatar

martinbean wrote a reply+100 XP

1mo ago

Deleting rows massively using DB facade

@imranbru You’ve pretty much just repeated my comment and examples, and added nothing extra? 🤷‍♂️

martinbean's avatar

martinbean wrote a reply+100 XP

1mo ago

Deleting rows massively using DB facade

Is it possible instead of using the primary key $id to use another field which is not the primary key?

@adamnet Yes? Just specify it?

DB::delete('DELETE FROM users WHERE some_other_column = ?', [$value]);

Alternatively, you can still use the query builder:

DB::table('users')->where('some_other_column', '=', $value)->delete();
martinbean's avatar

martinbean wrote a reply+100 XP

1mo ago

Multipart limitations

@vincent15000 What do you mean by “works” and “doesn’t work”?

We have no idea what data you’re sending, to where, what you expect to see, nor what you’re actually seeing.

martinbean's avatar

martinbean was awarded Best Answer+1000 XP

1mo ago

upgrading vsanilla php 5.4 to 8.x with laravel

@iamyannc Hey. I’ve done a lot of these type of re-factoring and re-platforming projects in the past. The way I’d approach it would be like this:

  • Get the application running on a newer version of PHP. So upgrade to 7, fix any usage of deprecated APIs and libraries, and then when possible upgrade to PHP 8 and do the same.
  • Once you’ve got the vanilla PHP application running on a modern version of PHP, create a new Laravel application and dump your legacy application’s file in the public directory.
    • Rename Laravel’s index.php file to something like laravel-index.php to avoid clashing with your legacy index.php file.
    • Tweak your .htaccess or nginx config to just load a file if it exists, or fall back to Laravel’s front controller.
  • You should now have a Laravel application, but with no requests actually being routed through it to start off with, and instead requests hitting your legacy application as before.
  • Slowly start re-factoring your legacy application to Laravel controllers, views, etc. Do this slowly, and one discreet part at a time. Trying to re-factor too much in one go just leads to lots of files being touched, none of them 100% converted, and the dreaded feeling of, “Urgh, I need to git reset this and start over.”
  • As you do the above, the number of files from the legacy application will decrease, and the number of Laravel files increase, until you’re left with nothing of the legacy application.

Happy for you to reach out if you have any questions. DM me on Twitter 𝕏 (https://x.com/martinbean) and I can share my email address.

martinbean's avatar

martinbean wrote a reply+100 XP

1mo ago

simple qr code and laravel 12 (with starter kit), not possible?

@sbrillo Fortify already requires the bacon/bacon-qr-code package at version 3 (https://github.com/laravel/fortify/blob/fc66a38872a0e304748336d2975f37672c8fca9c/composer.json#L19). The package you’re trying to install wants version 1 of that package, which suggests the package you’re trying to install is massively outdated.

So given Fortify already adds bacon/bacon-qr-code to your Laravel application, just use it directly. You don’t need to install a package to generate QR codes when there’s literally already one installed.

martinbean's avatar

martinbean wrote a reply+100 XP

1mo ago

upgrading vsanilla php 5.4 to 8.x with laravel

@iamyannc Hey. I’ve done a lot of these type of re-factoring and re-platforming projects in the past. The way I’d approach it would be like this:

  • Get the application running on a newer version of PHP. So upgrade to 7, fix any usage of deprecated APIs and libraries, and then when possible upgrade to PHP 8 and do the same.
  • Once you’ve got the vanilla PHP application running on a modern version of PHP, create a new Laravel application and dump your legacy application’s file in the public directory.
    • Rename Laravel’s index.php file to something like laravel-index.php to avoid clashing with your legacy index.php file.
    • Tweak your .htaccess or nginx config to just load a file if it exists, or fall back to Laravel’s front controller.
  • You should now have a Laravel application, but with no requests actually being routed through it to start off with, and instead requests hitting your legacy application as before.
  • Slowly start re-factoring your legacy application to Laravel controllers, views, etc. Do this slowly, and one discreet part at a time. Trying to re-factor too much in one go just leads to lots of files being touched, none of them 100% converted, and the dreaded feeling of, “Urgh, I need to git reset this and start over.”
  • As you do the above, the number of files from the legacy application will decrease, and the number of Laravel files increase, until you’re left with nothing of the legacy application.

Happy for you to reach out if you have any questions. DM me on Twitter 𝕏 (https://x.com/martinbean) and I can share my email address.

martinbean's avatar

martinbean wrote a reply+100 XP

1mo ago

Reverting from PEST to PHPUnit

@randy_johnson Pest is based on PHPUnit. Just take a look at the tests directory in the laravel/laravel repository for the skeleton files you need to go back to using PHPUnit.

martinbean's avatar

martinbean wrote a reply+100 XP

1mo ago

Multipart limitations

@vincent15000 What is your actual question?