I need to use an variable to make a query in other function. How i can do this?
public function getestados($nick)
{
$nivel = DB::table('locais')
->where('nick', $nick)
->get('nivel');
return $nivel->toJson(JSON_PRETTY_PRINT);
}
public function elevar($nivel) {
$novonivel = DB::table('niveis')
->where('cond', $nivel) // previous variable
->get();
return response()->json([$novonivel]);
}
2
Answers
It looks like you use
OOP
so it is recommended to use the property inside theclass
like thisbut if you call the second method separately from the first, you should store it in
session()->put('key', $nivel')
. and then get it in the second methodsession()->get('key')
// $nivel