'I want to assign a string value to a global variable inside the controller from database but it displays null
class atmcontroller extends Controller {
private $uniname;
public function loginvalidation(Request $request){
$this->validate($request, [
'username' => 'required',
'password' => 'required',
]);
$username = $request->input('username');
$password = $request->input('password');
$user = DB::table('atmuser')->where('username', '=', $username)->where('password', '=', $password)->get();
$usercount = $user->count();
$name = DB::table('atmuser')->where('username', '=' ,$username)->where('password', '=', $password)->pluck('name');
$this->uniname = (string)$name; **// i want to transfer the value from DB to this->uninmae.**
$balance = DB::table('atmuser')->where('username', '=' ,$username)->where('password', '=', $password)->pluck('balance');
if (!$usercount == 0) {
return view('transaction', ['name' => $name , 'balance' => $balance]);
}
else {
return view('login');
}
}
}
I want to transfer the value from the DB where it assign to $name to the global variable $this->uniname in order for me to use it as an parameters in if's and else.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
