Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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