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

mehmetanbaki's avatar

api controller

I have a system contain users, customers, companies, cards and items. Should I make everyone of them independent API Controller to prevent mistakes or I make one API Controller to all of them

0 likes
18 replies
tykus's avatar

Separate controllers for each resource.

... cards??? Not credit cards???

tykus's avatar

Can you tell me the name of this application that I should know to avoid??

tykus's avatar

You are going to store user's credit card details in your database.

Talinon's avatar

You have been hired by a bank to create an API for applications that consume credit card numbers?

I must know more about this bank?

tykus's avatar

Is this a real application, or something you are doing as a personal project that will never be used publicly?

If you are building a real world application, then you need to take so advice regarding accepting and storing credit card and personal information belonging to users.

mehmetanbaki's avatar

I'd love to. It will be so useful to me all the advises

mehmetanbaki's avatar

No I'm not hired by a bank it's some project I'm working on it and I hope to make it well

tykus's avatar

Ok, my advice is don't accept and store credit card numbers on your own servers

mehmetanbaki's avatar

Ok so how you suggest to do it in the right way ????

goldtaste's avatar
Level 8

Yes, you probably want separate controllers for each of these. It's likely that you will only end up calling two or three end points from a page (I'm guessing your are using vue or some sort of SPA) at the same time. Which isn't too much of a problem.

If you do end up making lots and lots of calls at the same time, then you may want to consider some sort of facade controller.

I would also recommend reading up on REST apis. May also be worth checking to see if there is anything on laracasts video section about creating apis. I'm pretty sure there will be.

laracasts_com's avatar

As everybody said, do make a separate controller for each, it is referred to as end-point.

users, customers, companies, and items are all valid end-points to have.

There is no reason to ever have an end-point for cards, unless you are working as a financial institution and building an app that does that. Better leave it out of tests system/project as well.

It would be far better to try Stripe / PayPal or any other payment gateway, almost all of them provide a testing system.

bugsysha's avatar

@tykus @talinon do you really think that banks do know what they are doing and that only experts work there? I had a chance to have an interview with major Italian bank just to see that they have no clue how things should be done.

mehmetanbaki's avatar

Schema::create('salaries', function (Blueprint $table) { $table->bigIncrements('id')->primary(); $table->string('init_salary'); $table->string('ssn'); $table->string('assurance_mount'); $table->string('bounces'); $table->string('bounce_type'); $table->string('deductions'); $table->string('deduct_type'); $table->string('total_salary'); $table->timestamp('paid_at'); $table->timestamps(); });

can you help me with that please ???

Please or to participate in this conversation.