1. Go to this page and download the library: Download girover/tree library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
use Girover\Tree\Models\Tree;
$tree = Tree::find(1);
$first_child_data = ['name'=>'first child', 'birth_date'=>'2001-01-01'];
$tree->pointerToRoot()->newChild($first_child_data ,'m'); // m = male
// Or you can do this instead
$tree->pointerToRoot()->newSon($first_child_data);
use App\Models\Tree;
$tree = Tree::find(1);
$pointer = $tree->pointer();
use App\Models\Tree;
use App\Models\Node;
$tree = Tree::find(1);
$node = Node::find(10);
$tree->pointer()->to($node);
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Node;
class PersonController extends Controller
{
public function addPhoto(Request $request)
{
$person = Node::find($request->person_id);
$photo = $request->file('photo');
$person->setPhoto($photo, 'new name');
return view('persons.index')->with('success', 'photo was added');
}
}
use App\Models\Node;
$node = Node::find(10);
$another_node = Node::find(30);
$node->moveTo($another_node);
use App\Models\Node;
$node = Node::find(10);
$another_node = Node::find(30);
$node->moveChildrenTo($another_node);
use App\Models\Node;
$node = Node::find(10);
$another_node = Node::find(30);
$node->moveAfter($another_node);
use App\Models\Node;
$node = Node::find(10);
$another_node = Node::find(30);
$node->moveBefore($another_node);
return $node->generation(); // int or null
use Girover\Tree\Models\Tree;
$tree = Tree::find(1);
$tree->pointer()->to('aa.aa')->father(); // move Pointer to location 'aa.aa' and then get its father.
$tree->pointer()->grandfather(); // get grandfather of node that Pointer indicates to
$tree->pointer()->ancestor(3); // get father of node that Pointer indicates to
$tree->pointer()->children(); // get children of node that Pointer indicates to
$tree->pointer()->sons(); // get sons of node that Pointer indicates to
$tree->pointer()->newDaughter($data); // create daughter for the node that Pointer indicates to
$tree->pointer()->newSon($data); // create son of node that Pointer indicates to
$tree->pointer()->newSister($data); // create sister for the node that Pointer indicates to
$tree->pointer()->newChild($data, 'm'); // create son for the node that Pointer indicates to
$tree->pointer()->firstChild(); // get the first child of node that Pointer indicates to
.
.
.
.
.
$tree->pointer()->toHtml();
use App\Models\Person;
$person = Person::create(['name'=>'Person', 'birth_date'=>'2000-01-01']);
$another_person = new Person;
$another_person->name = 'Another';
$another_person->birth_date = '2000-01-01';
$another_person->save();
use App\Models\Person;
$new_person = Person::where('name', 'new person')->first();
$person = Person::find(1);
$person->newSon($new_person);
//or
$person->createFather($new_person); // only if $person is a root in the tree
//or
$person->newBrother($new_person); // only if $person is not a root in the tree
//or
.
.
.
use App\Models\Person;
$person = Person::find(100);
$person->delete();
use App\Models\Person;
$person = Person::find(100);
$person->detachFromTree();
$detached = detachedNodeables();
$count_detached = countDetachedNodeables();
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Tree;
class TreeController extends Controller
{
public function index()
{
$tree = Tree::find(1);
$treeHTML = $tree->toHtml()
// OR
$treeHTML = $tree->toTree()
// OR
$treeHTML = $tree->Draw()
return view('tree.index')->with('treeHTML', $treeHTML);
}
}
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Tree;
use App\Models\Node;
class TreeController extends Controller
{
public function index()
{
$tree = Tree::find(1);
$person = Node::find(11);
$treeHTML = $tree->pointer()->to($person)->toHtml();
// OR
$treeHTML = $tree->pointer()->to($person)->toTree();
// OR
$treeHTML = $tree->pointer()->to($person)->draw();
return view('tree.index')->with('treeHTML', $treeHTML);
}
}
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Node;
class TreeController extends Controller
{
public function index()
{
$person = Node::find(11);
$treeHTML = $person->toHtml();
// OR
$treeHTML = $person->toTree();
// OR
$treeHTML = $person->draw();
return view('tree.index')->with('treeHTML', $treeHTML);
}
}
// AppServiceProvider
public function boot()
{
$this->app->singleton('nodeHtmlAttributes',function($app){
return function($nodeable){
return " data-id='{$nodeable->id}' data-name='{$nodeable->name}' data-gender='{$nodeable->gender}' data-is-died='{$nodeable->is_died}' ";
};
});
}
// AppServiceProvider
public function boot()
{
$this->app->singleton('nodeCssClasses',function($app){
return function($nodeable){
return ($nodeable->is_died) ? 'is-died' :'';
};
});
}
bash
php artisan tree:install
config\tree.php
config\tree.php
config/tree.php
$data
$data
html
<!-- views/tree/index.blade.php -->
<div>
@tree($treeHtml)
</div>
<!-- OR -->
<div>
{!! $treeHTML !!}
</div>
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.