How do I get User data in Array in Laravel

Amit Kumar
Sep 14, 2021

--

In this tutorial im going to learn how to get all user data in array.

First to create Controller

php artisan make:controller Youtube

Next to create Route go to web.php.

Route::get('/joins','Youtube@index');

Go to your controller Youtube.php and paste below code.

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;

class Youtube extends Controller
{
public function index()
{
$data=DB::table('users')->get()->toArray();
echo "<pre>";
print_r($data);
}
}

Now run below code.

http://127.0.0.1:8000/joins

Now data get successully from Users Table. Thanks πŸ‘πŸ‘

--

--

Amit Kumar
Amit Kumar

Written by Amit Kumar

Hi I am Amit Experienced Web Developer with a demonstrated history of working in the information technology and services industry.

No responses yet