seus
seus

Reputation: 568

Using YML file in Laravel

I have a YML file with a list of data, I would like to include the data in my laravel project but have no idea how. I am familiar with the symfony way using 'sfconfig'. But after a quick bit of research I am unable to even echo the yml data out in to my laravel view. In the end I would like to loop through the data and generate a usuable array

YML file data

ACT:
  city: Canberra
  regions:
    -
      key: Canberra
      name: Canberra
      slug: canberra

etc...

I am using Laravel 5, Thanks

Upvotes: 2

Views: 5968

Answers (2)

Peyman.H
Peyman.H

Reputation: 1952

why don't you use yaml_parse_file ?

First write extension=yaml.so without any quotes in your php.ini file.

And then:

$data = yaml_parse($yaml_file);
print_r($data);

$data is an array through which you can easily iterate!

Upvotes: 2

aalaap
aalaap

Reputation: 4411

Laravel internally uses the Symfony YAML component, so it's available for use readily in your project without adding any PHP extensions. Simply use it and call it:

use Symfony\Component\Yaml\Yaml;

...

print_r(Yaml::parse('a: b'));

Upvotes: 2

Related Questions