Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Parent controller for calling function from another controller
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Http\Controllers\ChildController;
class ParentController extends Controller
{
protected $ChildController;
public function __construct(ChildController $ChildController)
{
$this->ChildController = $ChildController;
}
/**
* Parent function using child function
*/
function calc(Request $Request){
$firstNumber = $Request->input('firstNumber');
$operator = $Request->input('operator');
$secondnumber = $Request->input('secondnumber');
$response = $this->ChildController->Calculation($firstNumber, $operator, $secondnumber);
return $response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment