Skip to content

Instantly share code, notes, and snippets.

@infinitbility
Created June 1, 2020 16:17
Show Gist options
  • Save infinitbility/042c9c38294be2fd4567dbfe5526ddfe to your computer and use it in GitHub Desktop.
Save infinitbility/042c9c38294be2fd4567dbfe5526ddfe to your computer and use it in GitHub Desktop.
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