I have the next code of my trait.
trait ObraTrait
{
public function custo(Request $request)
{
$custo = array_sum($request->custo);
if ($custo != 100.00) {
return back()->withInput()->with(
'danger','Custo equal to 100.00%'
);
}
}
}
and my controller
public function update(UpdateObra $request, $id)
{
$this->custo($request);
....
return redirect()->route('app.obras.index')->with(
'success','Obra Atualizada com Sucesso'
);
}
and the answer its…
I want the controller stop when $custo != 100, that it’s verified in the trait and back to the same page with a mensagem.
2
Answers
Modify your custo() method in the trait to throw an exception when the condition is not met, and then catch that exception in your controller.
Trait
Controller
another option: