Home > Back-end >  Laravel : Anyone know how to foreach api from database?
Laravel : Anyone know how to foreach api from database?

Time:02-18

im new to laravel

I Have this data on my database Tiktoks table :

Id Username
1 Example

And I have this on my controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Tiktok;

class DashboardController extends Controller
{
    public function index(Request $request)
    {
        $ttapi = new \Sovit\TikTok\Api(array());
        $username = Tiktok::select(['username'])
        ->get()
        ->toArray();

        $userinfo = $ttapi->getUser($username);

        return view('admin.dashboard.index', compact(['userinfo']));
    }
}

If you see in $userinfo i have $ttapi->getUser, how can I foreach everydata using 1 data from Tiktoks table?

CodePudding user response:

Just remove ->toArray() from your code

  • Related