Bladephp: Now with 8+ codeigniter, php, and laravel project 8+ php project From $37/Month From Rs. 2499/Month

How to retrieving all rows from a table in Laravel 5

by
Category:laravel
mysql laravel
How to retrieving all rows from a table in Laravel 5

We can retrieve all record in table to using table method on the DB facade to begin a query. Several methods to connect like, get(), first() etc, that helps to get table record using table method.

Let’s create a table method in laravel 5

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Requests;
use DB;


class PostController extends Controller
{
    public function addPost()
    {
        $getpost = DB::table('tbl_post')->get();
        return view('viewpost', ['getpost' => $getpost]);
    }
}

The get method returns an Illuminate\Support\Collection containing the results where each result is an instance of the PHP StdClass object.

foreach ($getpost as $post) {
    echo $post->title;
}

0 Comments


Html code work in comment box


Related Post