Answer the question
In order to leave comments, you need to log in
How to pass a variable from one controller function to another and call it from a file with routes?
I want to pass a variable from one public function to another (in the controller class) and call this function (with the passed variable) in the routes file in order to use this variable as a url there.
So, I have myController
, and I want to pass $Hash
from the first function to the second. I also want to make a route where I will use the function variable second
$Hash
as the url.
Here is what I did but it doesn't work.
( Firstly , I have an error:
Too few arguments to function App\\Http\\Controllers\\myController::second(), 1 passed and exactly 2 expected
class myController extends Controller
{
public function first(Request $request, $Hash)
{
$requested_email = $request->email;
$getUserByEmail = DB::table('users')->where('email', $requested_email)->first();
$Hash = Crypt::encrypt($getUserByEmail->password);
echo $Hash;
}
public function second($Hash)
{
echo $Hash;
}
}
Route::get('{Hash}', '[email protected]');
route::post('url', '[email protected]')
Answer the question
In order to leave comments, you need to log in
And if you declare a variable in the controller before the functions?
and then in the first function:
private $Hash = '';
public function first(Request $request, $Hash)
{
$requested_email = $request->email;
$getUserByEmail = DB::table('users')->where('email', $requested_email)->first();
$this->Hash = Crypt::encrypt($getUserByEmail->password);
echo $this->Hash;
}
public function second($this->Hash)
{
echo $this->Hash;
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question