I want to make a simple Laravel calculator, but I'm not sure where to define my class and where to use the functions. Do I define my class as a Model? And where do I calculate the result? Do I do it in the controller?
Say I made a class somewhere
class Calculator
{//other methods here...
public function add($a, $b)
{
return $a + $b;
}
}
And in a certain controller I should have something like this
$a= $request->input('first');
$b= $request->input('second');
But where do I define a new Calculator and make the addition? Do I do it in the same controller as well?
$calc=new Calculator();
$result=$calc->add($a,%b);
This obviously goes in the controller, but do I have to do the addition somewhere else and pass it to the controller?
return view('pages.result')->with('result',$result);