To begin with the user selects a value from the dropdown list which stores the selected value in a variable called $SetNumber
which is located in ControllerOne
. Once the user selects from the dropdown as you cans see the form action is /Update
which is used to retrieve and redirect the data to ControllerTwo
<form method="POST" action="/Update">
@csrf
<select name="Match" id="Match" onchange="this.form.submit()">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
</form>
ControllerOne
contains an empty
variable, which defines the variable $SetNumber
. ControllerOne
:
class ControllerOne extends Controller
{
public function index()
{
$SetNumber = "";
}
public function update(Request $request)
{
$SetNumber = $request->Match;
return redirect()->action('ControllerTwo@index', ['SetNumber' => $SetNumber]);
}
}
class ControllerTwo extends Controller
{
public function index()
{
echo $SetNumber;
return view('pages.viewpage')->with('SetNumber', $SetNumber);
}
}
The problem is that when I try to echo $SetNumber
within my controller and return it to my view , prompts me with this error:
Undefined variable: SetNumber.
how could I do this better?
i am new to laravel and web dev.