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

jrdavidson's avatar

More API questions

I am still struggling with the concept of what do in the situation of I believe an API.

I have my site project that I want to keep on my own hosting and then I have a few websites that will be using this application.

Just to get more understanding of what I need to do. When someone accesses the register route on a site that utilizes my script I want them to be able to use my RegistrationController@create method. I have that set up on my application routes but how can I fix it so that any site will use registration controller.

www.site1.com/register www.site2.com/register www.site3.com/register

is handled by mysite.com/register

0 likes
11 replies
davorminchorov's avatar

Ok, so you want multiple websites to use your API, right?

These websites have their own /register page, so when they send a POST request to your API URL (domain.com/api/register for example), that API URL will hit RegistrationController@create.

Your API routes.php file
Route::group(['prefix' => 'api'], function(){
post('register', 'RegistrationController@create'); // or the facade Route::post();
});
jrdavidson's avatar

So your saying I can't do something like this:

Route::group(['prefix' => 'v1'], function ()
{
    Route::get('login', ['as' => 'login_path', 'uses' => 'SessionsController@create']);
    Route::post('login', ['as' => 'login_path', 'uses' => 'SessionsController@store']);

    Route::get('registration', ['as' => 'registration_path', 'uses' => 'RegistrationController@create']);
    Route::post('registration', ['as' => 'registration_path', 'uses' => 'RegistrationController@store']);
    Route::get('registration/verify/{confirmation_code}', ['as' => 'confirmation_path', 'uses' => 'RegistrationController@confirm']);

    Route::get('dashboard', ['as' => 'dashboard', 'uses' => 'DashboardController']);
});
jrdavidson's avatar

Upon further explanation inside of a chat it was brought to my attention I may need to rethink all of this because I am confusing people on what I am wanting to accomplish.

I am wanting to finish developing an application that is a CMS that is a monthly payable service that a certain type of industry can take advantage of. All companies will be storing their data in my database on my server. This means their users, news articles, events, etc. This way I can be the super administrator that can help monitor the sites data.

I have say the login, register, and account verification features implemented by want to go back and work on this so that its easier down the road when I actual start on the admin panel for this project.

Any suggestions?

uxweb's avatar

You can use guzzle to make an API call from your other sites/apps controllers. I think you mean this?

jekinney's avatar

I believe the easiest way would be a JavaScript file that has the Ajax call set up. So the client site only needs to implement the form. Suggests an https request.

Plan b which I have done, and currently do for store fronts. Is host the required pages myself via a domain redirect ( so it looks like the clients URL) to the pages I have for their requirements. Issue is having to match to clients sites theme/layout.

davorminchorov's avatar

Yeah sure, you can do that, but if you are creating an API, you'll have to return json instead of a normal laravel blade view.

You have to present your data as json, so the developers who work on those sites, can make API calls and get the data or post data to it. They have to implement their own front end and use your data.

jrdavidson's avatar

Can someone show me an example of what they mean?

davorminchorov's avatar

So you are returning normal views which means, you are building a normal web app instead of an API. Watch the Incremental APIs series again and see the differences.

Maybe you want to build it first as a normal web app and then move on to building the same app as an API. If that's your plan, you are on the right path.

1 like
pmall's avatar

You want people to register on your main site but have their own installation ? Ive never seen nothing working like this.

Anyway, so you can think of your main website as a big database answering json to api calls, and all the small sites are just the front end fiering api calls and doing something with the json.

But again, it will be hard to achieve. Youd better keep all on the main site (multi tenancy application) and let them point their own domain to their space on your main website (wordpress.com like).

I believe the easiest way would be a JavaScript file that has the Ajax call set up.

No cross domain ajax call, it wont work. Forbidden by the browsers (hopefully !).

jekinney's avatar

@pmall

Lol, sorry, meant js file with API endpoints set for Ajax call and have the client implement the html pages required.

Please or to participate in this conversation.