PHP code example of falco442 / lumen-treeview
1. Go to this page and download the library: Download falco442/lumen-treeview 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/ */
falco442 / lumen-treeview example snippets
namespace App\Http\Controllers;
use App\Models\Post;
use falco442\Treeview;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
class PostsController extends Controller
{
public function tree()
{
$posts = Post::all()->transform(function ($item) {
if ($item->parent_id === 0) {
$item->parent_id = null;
}
return $item;
})->toArray();
return \response()->json(Treeview::getTree($posts));
}
}
namespace App\Http\Controllers;
use App\Models\Post;
use falco442\Treeview;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
class PostsController extends Controller
{
public function tree()
{
$posts = Post::all()->transform(function ($item) {
if ($item->parent_id === 0) {
$item->parent_id = null;
}
return $item;
})->toArray();
return \response()->json(Treeview::getTree($posts, 101));
}
}