Create View to get login details

I have to tables with employee details in one table and his/her password details in another table. So i need to write a view to get password of the employee from another table using his id(employee id).

Can anyone help me with this? It is very easy I know but I am getting stuck.

use a JOIN on that user id

Getting a users password shouldn’t be an easy thing. It means you are storing passwords in a way that is retrievable, and that is always bad.

Yes but in the database that we are using we have two tables, in one we store all employee data and in another we store thier passwords. So in order to login i want to create a view wherein i can use it in laravel for login.

still just join them in your view.

CREATE
ALGORITHM = UNDEFINED
DEFINER = root@localhost
SQL SECURITY DEFINER
VIEW travel_db.logindetails AS
SELECT
tools_bta.employee_main_db.tgi AS employeeid,
tools_bta.emp_username_db.id AS id,
tools_bta.emp_username_db.emp_id AS emp_id,
tools_bta.emp_username_db.password AS password,
tools_bta.emp_username_db.cpass AS cpass,
tools_bta.emp_username_db.chpass AS chpass,
tools_bta.emp_username_db.date AS date,
tools_bta.emp_username_db.tgi AS tgi,
tools_bta.emp_username_db.field2 AS field2,
tools_bta.emp_username_db.isAdmin AS isAdmin
FROM
(tools_bta.emp_username_db
JOIN (tools_bta.employee_main_db
JOIN travel_db.users))
WHERE
(tools_bta.emp_username_db.tgi = tools_bta.employee_main_db.tgi)
GROUP BY tools_bta.emp_username_db.id

This is how i have created the view to fetch all records. Now how do I use this view for custom login in laravel?

just type your SELECT statement on that view as table name - like anywhere else.

$mgrEmp = DB::select(“SELECT * FROM travel_db.logindetails”);

This is how I have done!!! Not in Eloquent format as its giving me some errors. Is this correct?

Does it give you the expected results?

Yes I am getting all records but I want in Eloquent format.

so what does the documentation tell you about “eloquent format”?

Sponsor our Newsletter | Privacy Policy | Terms of Service