How to fetch all rows of a table in laravel?
We will use DB class for this. Suppose we have a table. Name of the table is table1.
Firstname | Lastname |
Harry | Potter |
Tom | Riddle |
This will be a table in database, I am showing this here just for understanding.
Lets see the code to fetch all rows of this table.
use Illuminate\Support\Facades\DB;
class NameofClass {
public function getTableData( Request $request ) {
$allRows = DB::table('table1')->get();
return $allRows;
}
}
This function return value will be
[{“Firstname“:”Harry”,”Lastname“:”Potter”},{“Firstname“:”Tom”,”Lastname“:”Riddle”}]