Skip to content

Instantly share code, notes, and snippets.

@infinitbility
Created June 1, 2020 16:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save infinitbility/ca5a4cccc2952dcf0dc29e1a8c5730ea to your computer and use it in GitHub Desktop.
Save infinitbility/ca5a4cccc2952dcf0dc29e1a8c5730ea to your computer and use it in GitHub Desktop.
Child controller for calling function from another controller
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
class ChildController extends Controller
{
/**
* Common function using on multiple controller
*/
public function Calculation($firstNumber, $operator, $secondnumber){
if($operator == '+'){
$response = $firstNumber + $secondnumber;
}elseif($operator == '-'){
$response = $firstNumber - $secondnumber;
}elseif($operator == '*'){
$response = $firstNumber * $secondnumber;
}elseif($operator == '/'){
$response = $firstNumber / $secondnumber;
}
return $response;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment