这是我的计算器类的代码,它有4个函数,加,减,乘和除。这需要两个输入。我想创建一个类,而不是可以接受2个以上的输入并返回答案。我正在使用laravel来制作这个计算器。
这是我的控制器方法
B
以下是用于计算的oop Maths类
public boolean equals (Object other)
这是我的观点calculator.blade,php
public function calculate()
{
$oprator;
$input = Input::get('ans');
$logs = new Log;
$logs->user_id = Auth::id();
$logs->log_data = $input;
preg_match_all('/\d+/', $input, $matches);
if (preg_match('/[\/\'^£$%&*()}{@#~?><>,|=_+¬-]/', $input,$oper))
{
$oprator = $oper[0];
}
$firstnumber = $matches[0][0];
$secondnumber = $matches[0][1];
$Maths1= new Maths();
if($oprator == "+"){
$data=array('answer'=> $Maths1->add($firstnumber,$secondnumber));
$logs->log_answer = $data['answer'];
$logs->save();
return view('calculator',compact('data'));
}
if($oprator == "-"){
$data=array('answer'=> $Maths1->subtract($firstnumber,$secondnumber));
$logs->log_answer = $data['answer'];
$logs->save();
return view('calculator',compact('data'));
}
if($oprator == "/"){
$data=array('answer'=> $Maths1->divide($firstnumber,$secondnumber));
$logs->log_answer = $data['answer'];
$logs->save();
return view('calculator',compact('data'));
}
if($oprator == "*"){
$data=array('answer'=> $Maths1->multiply($firstnumber,$secondnumber));
$logs->log_answer = $data['answer'];
$logs->save();
return view('calculator',compact('data'));
}
}
}
我想在laravel
中使用加法,减法,除法和乘法来制作基本计算器