Summer Sale! All accounts are 50% off this week.

martinbean's avatar

martinbean wrote a reply+100 XP

1d ago

Laravel PHPUnit in CI/CD: Every Route Returns 404 During Tests

@leknoppix-708669 How about you just answer my question, instead of providing lots of things I didn’t ask about…?

Show your routes file and how you’re actually registering these routes.

martinbean's avatar

martinbean wrote a reply+100 XP

1d ago

Laravel PHPUnit in CI/CD: Every Route Returns 404 During Tests

@leknoppix-708669 All of your errors are 404s pointing to not being able to find routes, yet you show absolutely nothing around how you’re actually registering routes.

So, how are you actually registering routes?

My guess is you’ve got some sort of dynamic hostname, and you‘re taking this into account across environments given your tests pass in one environment but not another.

martinbean's avatar

martinbean wrote a reply+100 XP

5d ago

martinbean's avatar

martinbean wrote a reply+100 XP

5d ago

How to manage different data for a customer

@yougotnet I’ve worked on plenty of “multi-tenant” applications like this. Just keep things simple by using foreign keys and route parameters.

For example, one of my projects is a multi-tenant CMS (like Wix or Squarespace). When a user logs into the admin panel, if they belong to multiple websites then they can pick which website they want to manage. When they do, they’re then just redirected to the dashboard route (/websites/{website}/admin). The route group looks like this:

Route::group([
    'middleware' => ['auth', 'can:update,website'],
    'prefix' => 'websites/{website:slug}/admin',
], static function (): void {
    Route::get('/', DashboardController::class)->name('website.admin.dashboard');

    // Other website admin routes...
});

Each controller action then gets the current website injected as a parameter, so you can then scope model queries to that website:

namespace App\Http\Controllers\Admin;

class ArticleController extends Controller
{
    public function index(Website $website)
    {
        $articles = $website->articles()->paginate();

        return view('admin.article.index', compact('website', 'articles'));
    }

    public function store(Website $website, StoreArticleRequest $request)
    {
        $article = $website->articles()->create($request->validated());

        return redirect()
            ->route('website.admin.article.index')
            ->with('success', 'Article created.');
    }
}
martinbean's avatar

martinbean was awarded Best Answer+1000 XP

5d ago

NativePHP mobile — session/token lost on redirect after login (bounces back to login, then 419)

@randy_johnson Ignoring AI has been used to either generate or part-generate this question, mobile apps are a process that runs on the device. It’s client-side. They don’t have things like “sessions”. So you should be obtaining a token, and then storing that token in secure storage like the device’s keychain.

martinbean's avatar

martinbean wrote a reply+100 XP

5d ago

martinbean's avatar

martinbean wrote a reply+100 XP

6d ago

NativePHP mobile — session/token lost on redirect after login (bounces back to login, then 419)

@randy_johnson Ignoring AI has been used to either generate or part-generate this question, mobile apps are a process that runs on the device. It’s client-side. They don’t have things like “sessions”. So you should be obtaining a token, and then storing that token in secure storage like the device’s keychain.

martinbean's avatar

martinbean wrote a reply+100 XP

1w ago

UX design for smartphone and several columns

@vincent15000 Yes, that was a typo. I meant to write “horizontally scrollable”.

martinbean's avatar

martinbean wrote a reply+100 XP

1w ago

UX design for smartphone and several columns

@vincent15000 Either make the table horizontally scalable, or stack the columns on smaller viewports.

martinbean's avatar

martinbean wrote a reply+100 XP

1w ago

Update a customer's code which was initially given wrong

@adamnet Awesome! Are you using version control yet?

martinbean's avatar

martinbean wrote a reply+100 XP

1w ago

Imagick not automatically included in Forge anymore.

@dnabeast Did Forge ever say they would definitely install Imagick when provisioning servers? I don’t use Forge, so don’t know what guarantees they make in terms of supported PHP extensions. I also don’t know why you’re then linked to the Herd docs; Herd has nothing to do with Forge and vice versa.

If you require Imagick then I think you will need to put that in your provisioning script. Googling "laravel forge imagick" yielded this result: https://forgerecipes.com/recipes/291/install-enable-imagick-on-php84 (you’ll need to tweak it if you’re using a version of PHP other than 8.4).

martinbean's avatar

martinbean wrote a reply+100 XP

1w ago

How do you sanitize user input data?

@eylay This thread was over half a decade old…

martinbean's avatar

martinbean liked a comment+100 XP

2w ago

The Build A Forum Course

Thank you Martin that is most helpful.

martinbean's avatar

martinbean wrote a reply+100 XP

2w ago

How to review AI-generated code

@phpmick You should be in control of any and all code making its way into your codebase, whether that’s written by you, a colleague, or an LLM. Here are some tips and guidelines I follow when doing AI-assisted development:

  • Give agents very discreet tasks to complete.
  • When you’re prompting the agent, ask it to ask you about anything it’s unsure of instead of guessing. You’ll find you’ll get something far more in line with what you had in mind and were expecting, instead of giving an agent a loose description, and it making assumptions and making something that’s maybe 60% of what you wanted.
  • Give agents way to verify the work they’re producing. There should be a goal, as well as instructions on how to run any tool such as linting and testing tools. If linting/tests fail, the agent should go back and fix what’s broken before asking for your attention.
  • Agents should also be given guardrails to avoid getting stuck in a loop and burning tokens.
  • You should only be merging code you actually understand. If you don’t, review the agent output log. If you’re still unsure, then ask the agent to explain what it’s produced. As with human-produced code, less code is easier to grok than lots of code. Don’t have your agent spew out 50,000 lines of code and then review.
martinbean's avatar

martinbean wrote a reply+100 XP

2w ago

How to secure an API-generated video embed link and prevent user sharing?

@shivamyadav Never heard of “UIshare” but you shouldn’t be serving static video files (i.e. MP4s) if this is content you want to control access to.

I’d add another recommendation for something like Mux as well. They will probably deliver video as HLS streams, require the use of signed URLs for playback, and you can even add DRM if you want to go down that route.

I’ve ran a video on demand platform for over 10 years now. I used to use Amazon for storing, transcoding, and delivering video; but moved to Mux maybe three years ago now and it’s far cheaper and easy to integrate. It’s to video what Stripe is to payments.

martinbean's avatar

martinbean wrote a reply+100 XP

2w ago

Printer selections from laravel

@gp10devhts No. Printing is a client-side concern.

It would be a huge security issue if a PHP app hosted on some random server somewhere in the world could see what devices (including printers) were on your network.

martinbean's avatar

martinbean wrote a reply+100 XP

2w ago

In-app browsers Socialite w/Google Access Blocked

@kn_swe Can you post the full error message?

martinbean's avatar

martinbean was awarded Best Answer+1000 XP

3w ago

Recently Started Paying for AI

@randy_johnson There’s no magic fix. If you just let AI go wild and just approve everything it does then yeah, your codebase is going to become unmanageable and full of slop. So you need to be specific in your directions and more meticulous on what AI-authored changes you allow into your codebase.

martinbean's avatar

martinbean wrote a reply+100 XP

3w ago

How to implement Meta Offline Conversions in a Laravel application?

@ismaelaek Don’t know why you want to make your life easier by not using the SDK provided by Meta/Facebook. If that’s the case, then you’ll need to read the API reference and implement the HTTP requests (and everything around it such as authorisation and response handling) yourself from scratch.

martinbean's avatar

martinbean wrote a reply+100 XP

3w ago

Tracking transferred bytes on the client side?

@shivamyadav This sounds like something you’d be able to do with server logs. But, as with most of your questions, my question is: why? Are you really going to be billing users for say, downloading style sheets? 😕

martinbean's avatar

martinbean wrote a reply+100 XP

3w ago

Recently Started Paying for AI

@randy_johnson There’s no magic fix. If you just let AI go wild and just approve everything it does then yeah, your codebase is going to become unmanageable and full of slop. So you need to be specific in your directions and more meticulous on what AI-authored changes you allow into your codebase.

martinbean's avatar

martinbean wrote a reply+100 XP

3w ago

The Build A Forum Course

@puzbie The two things to look out for will be:

  1. The skeleton directory structure changed slightly from (I think) Laravel 11. The bootstrapping process was made a bit slimmer.
  2. Years later, Laravel still can’t decide how new projects should be created and Jetstream became deprecated in favour of “starter kits”. But looking at Jetstream’s composer.json file, it seems to be compatible with Laravel 13, so you should still be able to install it.
martinbean's avatar

martinbean liked a comment+100 XP

3w ago

Eloquent inside a migration ?

Error text?..

Are you sure Eloquent in migrations is good? Migrations are about raw database tables/columns, Eloquent is about models which are "next level" compared to DB calls. Sometimes they align, sometimes not. You cannot guarantee your migrations chain is consistent and always replayed with this approach.

I believe you need something like this: https://github.com/TimoKoerber/laravel-one-time-operations

It's like migrations for data, not structure.

martinbean's avatar

martinbean wrote a reply+100 XP

3w ago

Return back to a page with Infinite Scroll

You prefer using simple navigation links ?

@vincent15000 Yes. And I dare say a lot of your users would say the same.

martinbean's avatar

martinbean wrote a reply+100 XP

1mo ago

Return back to a page with Infinite Scroll

@vincent15000 This is exactly why I don’t like (or implement) “infinite” scroll. It’s a pain in the ass for users.

martinbean's avatar

martinbean wrote a reply+100 XP

1mo ago

Multiplayer Game Using Livewire?

@joahi93 You signed up, just to reply to a 2-year-old thread…?

martinbean's avatar

martinbean wrote a reply+100 XP

1mo ago

Contract/Interface for Eloquent models

Then when being processed by the job the 'status' field would get updated. Of course this is something the job shouldn't care about, so I thought well this is where a Contract/Interface would come in handy.

Is this a concept? Basically a Contract/Interface for Eloquent models.

@lsvagusa Yes. That’s the very definition of depend on interfaces, not implementations (the “L” in “SOLID”).

You would type-hint the interface in your job’s constructor, and then your job would call methods defined by that interface without knowing the actual class implementing that interface.

interface HasStatus
{
    public function updateStatus(string $newStatus);
}
class UpdateStatusJob implements ShouldQueue
{
    use Queueable;

    public HasStatus $model;

    public function __construct(HasStatus $model)
    {
        $this->model = $model;
    }

    public function handle(): void
    {
        $this->model->updateStatus('complete');
    }
}

Your job now doesn’t care if it’s working with an Eloquent model, or if it’s working with an Eloquent model at all. Just so long as the class it receives implements the HasStatus interface.

martinbean's avatar

martinbean wrote a reply+100 XP

1mo ago

DB schema for marriage?

@jlrdw This question was over a decade old. That marriage has kids in middle school now! 😄

martinbean's avatar

martinbean wrote a reply+100 XP

1mo ago

How big of projects do I need to get a job?

@june92 Seriously, how many questions are you going to ask on this topic…?

You keep asking questions that if you do X, you will magically be a senior developer, or if you do Y, you will magically get a job. That’s not how the industry works.

martinbean's avatar

martinbean wrote a reply+100 XP

1mo ago

GHSA-5vg9-5847-vvmq CRLF injection vulnerability in Laravel's email validation

Shouldn't this at least deserve a 11.x patch?

@gravity_global No, because Laravel 11 stopped receiving security updates March 12th, 2026: https://laravel.com/docs/13.x/releases#support-policy

martinbean's avatar

martinbean wrote a reply+100 XP

1mo 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

1mo 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

1mo 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

1mo 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

1mo 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

1mo 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

1mo 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

1mo 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

1mo ago

martinbean's avatar

martinbean wrote a reply+100 XP

1mo 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

1mo 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

2mos 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

2mos 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

2mos 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

2mos 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

2mos 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

2mos 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.