I'm new to Laravel and working on a simple project where in my controller (TestController) i have two functions (process & show).
What i'm trying to do is pass $email variable between the functions, so i can use it within the show function, but i don't know how to do that.
Controller
class TestController extends Controller
{
public function process(Request $request){
if($request->ajax()) {
$email = $request->get( "fullemail" );
}
}
public function show(){
}
}
Any help would be appreciated. Thanks in advance :)
EDIT
I'm edited my code as followed. Currently i get Too few arguments to function App\Http\Controllers\TestController::show(), 0 passed and exactly 1 expected
Error.
Controller
class TestController extends Controller
{
public function process(Request $request){
if($request->ajax()) {
$email = $request->get( "fullemail" );
$this->show($email);
}
}
public function show($email){
dd($email)
}
}
If you have reached laravel and know what functions are, you probably already know how to do this:
class TestController extends Controller
{
public function process(Request $request){
if($request->ajax()) {
$email = $request->get( "fullemail" );
$this->show($email);
}
}
public function show($email){
// Do whatever you will with the $email variable.
return view('some.view', ['email' => $email]);
}
}
An alternative approach:
class TestController extends Controller
{
// Declare this variable as a class property - protected means, that only this class and any class that inherits from this class can access the variable.
protected $email;
public function process(Request $request){
if($request->ajax()) {
$this->email = $request->get( "fullemail" );
$this->show();
}
}
public function show() {
// Do whatever you will with the $email variable.
return view('some.view', ['email' => $this->email]);
// On top of that, if you change $email value here, the changes will be available in all other methods as well.
// $this->email = strtolower($this->email);
}
}