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

NinjaJoe's avatar

Laravel: One File with Two Classes?

In Laravel, is it possible to have one file with two custom classes? E.g.:

In app/Portal.php, I have two custom classes, Portal and PaymentLogs:

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Portal
{
	public static function state($abbreviation)
	{
		// ...
	}
}

class PaymentLogs extends Model
{
	// ...
}

Is that possible?

If yes, how can I call each class from another file, like a view or controller? I'm looking for something like:

\App\Portal::PaymentLogs::create();

How can I call the PaymentLogs class in from app/Http/Controllers/PortalController.php and the state() method from the Portal class?

0 likes
4 replies
jeroenvanrensen's avatar

Hi @ninjajoe,

I do know it's possible, but I do not recommend it because it's a lot cleaner if it's divided to two files. For more information, you can watch this serie on Laracasts about the PHP OOP fundamentals.

I hope I did help you.

Jeroen

1 like
NinjaJoe's avatar

Hi guys, thank you for your advice. I will listen and stick to using only one class per file.

Please or to participate in this conversation.