3

I'm in the process of Developing APIs for a System whose front end is Android. App calls the API with lat and lon.

I am using Laravel for this and have developed some APIs already. I've also created separate controllers for each and is working correctly.

However 2 (Calculate Distance from Latitude and Longitude and return nearest ones in Ascending order) of the functions are used commonly almost in 3 or 4 Controllers: BusinessController , OfferController, OutletController. I thought it would be better to reuse the code passing parameters correspondingly.

Where should I place the common functions and how should they be invoked? Here is the code for controller.php

<?php namespace App\Http\Controllers;

use Illuminate\Foundation\Bus\DispatchesCommands;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;

abstract class Controller extends BaseController {

    use DispatchesCommands, ValidatesRequests;

}

PS: I'm somewhat new to Laravel.

1 Answer 1

4

In Laravel 5, the App folder is autoloaded. Create a folder or just a file somewhere in it:

<?php

namespace App; // Or App\Yourfolder

class YourSpecialClass
{
   // Your methods
}

And in your controller, just simply use App\YourSpecialClass;

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for Clarifying

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.