in laravel when we edit data than get only one dimensonal array it not required foreach loop thus we get single row by first and find method same way we use value() method for getting single row single value.
laravel sinle row getting methods
- first()
- find()
- findOrFail()
- value()
first()
laravel query builder first() method get first matching row in table query given in example. output of given example is first employee data which salary equal to 5000.
$employ = DB::table('employees') ->where('salay', '5000') ->first();
find()
laravel query builder find() method get data according to primary column value query given in example. output is find employee which id equal to 5.
$employ = DB::table('employees')->find(5);
findOrFail()
laravel query findOrFail() get data to given id and if id not found in record that it give not found page in output.
$employ = DB::table('employees')->findOrFail(5);
value()
how to get only single value from databse table than we use value method it take only one value of a particular column and row. in given example it get email id which id is 4.
$employ = DB::table('employees')->where('id', '4')->value('email');
watch all query builder playlist click on sidebar playlist link
Anmol Sharma
I am a software engineer and have experience in web development technologies like php, Laravel, Codeigniter, javascript, jquery, bootstrap and I like to share my deep knowledge by these blogs.
Related tutorial links
- laravel query builder introduction tutorial
- part 1 laravel query insert data
- part 2 laravel all type of where conditions in query builder
- part 3 laravel whereDate, whereYear and whereTime qyery method
- part 4 compare two db columns in laravel query builder
- part 6 laravel pluck method get single column value
- part 7 laravel select and addselect query in query builder
- part 5 laravel first and find queries
- part 8 laravel edit and update method query explaination
- Part 9 laravel query for update or insert data by one method
- part 10 laravel delete vs truncate vs drop method
- part 11 gropupby and orderby query tutorial
- Part 12 laravel union of two queries
- part 13 laravel all aggregate functions with example
- part 14 laravel query builder chunk method
- part 15 laravel exists() and doesntExist() method
- part 16 laravel paginate vs simplePaginate method
- part 17 laravel all join methods