Skip to content

Package for Laravel based on Eloquent to manage XML files

License

Notifications You must be signed in to change notification settings

proengsoft/laravel-xmlmodel

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

47 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#XmlModel Latest Stable Version Total Downloads Latest Unstable Version License

Package for Laravel based on Eloquent to manage XML files with SimpleXMLElement and xpath.

##Usage Install the package through Composer.

Edit 'app/config/app.php', and add a new item to the 'aliases' array:

'Salvaon' => 'Markcell\Salvaon\Salvaon'

Publish configuration file from package:

php artisan config:publish markcell/salvaon

You may now edit these options at 'app/config/packages/markcell/salvaon/config.php'. Or copy this file to 'app/config' folder with name 'salvaon.php'.

Now, your XML models can simply extend 'Salvaon':

<?php

class Breakfast extends Salvaon {

    /**
     * The file associated with the model
     *
     * @var string
     */
    protected $file = 'breakfast.xml';
   
    /**
     * Root element of the document
     *  
     * @var string
     */
    protected $root = 'breakfast';  
 
    /**
     * Child elements of the root
     * 
     * @var string 
     */
    protected $child = 'food';     
 
    /**
     * The primary key for the model
     *
     * @var string
     */
    protected $primaryKey = 'name';

}

See example of 'breakfast.xml' file on this link: https://github.com/markcell/salvaon/blob/master/breakfast.xml

##Examples

// Get all child nodes from XML root.
$foods = Breakfast::all();


// Count elements from selected childs $foods.
$foods->count();


// Get child from XML by $primaryKey or fail if not exists.
Breakfast::findOrFail('French Toast');


// Get child from XML with where condition.
$food = Breakfast::select()->where('name', '=', 'French Toast')->get();

// Update fields from selected child $food. 
$food->price = '3.25€';
$food->calories = 450;

// Save changes.
$food->save();


// Create new XML child.
$new = new Breakfast;

// Add data to child fields.
$new->name = 'French Toast';
$new->price = '4.50€';
$new->description = 'Thick slices made from our homemade sourdough bread';
$new->calories = 600;

// Save new child to XML file with tag attributes.
$new->save(array('id' => 26092014));

##License Licensed under the MIT license.

About

Package for Laravel based on Eloquent to manage XML files

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%