Ranjith M
Ranjith M

Reputation: 529

get the google fonts list in page

i'm using laravel now i want to list all the google web fonts in my page using google font api

public function index(){

function get_google_fonts() {
    $url = "https://www.googleapis.com/webfonts/v1/webfonts?key=!";
    $result = json_response( $url );
        $font_list = array();
        foreach ( $result->items as $font ) { 

            echo $font;             
        }
        return $font_list; 

    }
  return view('website_settings');
}

i think it's not working, can anyone help me please!

Upvotes: 1

Views: 930

Answers (1)

Alex Meyer
Alex Meyer

Reputation: 235

because $font is an object you have to traverse.. try something like that

$url = "https://www.googleapis.com/webfonts/v1/webfonts?key=!";
$result = json_decode(file_get_contents( $url ));
$font_list = "";
foreach ( $result->items as $font )
{
    $font_list[] = [
        'font_name' => $font->family,
        'category' => $font->category,
        'variants' => implode(', ', $font->variants),
        // subsets
        // version
        // files
    ];
}
return $font_list;

Upvotes: 3

Related Questions