For getting every new tutorial link Please join our telegram group

part 5 how to get single array from table in laravel query using first and find method

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

  1. first()
  2. find()
  3. findOrFail()
  4. 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

php laravel developer anmol sharma

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