Laravel 6 tree view Plugins using jQuery Example

Today, We want to share with you Laravel 6 tree view Plugins using jQuery Example.In this post we will show you wordpress plugin require another plugin, hear for Laravel 6 – category treeview hierarchical structure example with demo, we will give you demo and example for implement.In this post, we will learn about Laravel 6 bootstrap treeview example in table with an example.

Laravel 6 tree view Plugins using jQuery Example

There are the Following The simple About Dynamic Treeview with jQuery & Laravel PHP Framework Example Full Information With Example and source code.

As I will cover this Post with live Working example to develop Dynamic Tree With JSTree, PHP Laravel 6 And MySQL, so the Laravel 6 Tree View Application Directory Structure is used for this example is following below.

Read Also:  How to upload Profile Images to Users using Laravel 6?

Phase 1: Create a Laravel 6 categories table and model

Laravel 6 php artisan command.

php artisan make:migration create_categories_table

create a Laravel 6 create categories table for path database/migrations

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateCategoriesTable extends Migration
{
    public function up()
    {
        Schema::create('categories', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->text('parent_id');
            $table->timestamps();
        });
    }
    public function down()
    {
        Schema::drop("categories");
    }
}

app/Menu.php

<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Menu extends Model
{
   //menu has childs
   public function childs() {
           return $this->hasMany('App\Menu','parent_id','id') ;
   }
}

Phase 2: Add a Laravel 6 Route and Controller

routes.php

Route::get('example-tree-view',array('as'=>'example.treeview','uses'=>'[email protected]'));

app/Http/Controllers/TreeController.php

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Menu;
class TreeController extends Controller {
   public function treeView(){       
        $Categorys = Menu::where('parent_id', '=', 0)->get();
        $tree='<ul id="browser" class="filetree"><li class="tree-view"></li>';
        foreach ($Categorys as $Menu) {
             $tree .='<li class="tree-view closed"<a class="tree-name">'.$Menu->name.'</a>';
             if(count($Menu->childs)) {
                $tree .=$this->childView($Menu);
            }
        }
        $tree .='<ul>';
        // return $tree;
        return view('files.treeview',compact('tree'));
    }
    public function childView($Menu){                 
            $source ='<ul>';
            foreach ($Menu->childs as $product) {
                if(count($product->childs)){
                $source .='<li class="tree-view closed"><a class="tree-name">'.$product->name.'</a>';                  
                        $source.= $this->childView($product);
                    }else{
                        $source .='<li class="tree-view"><a class="tree-name">'.$product->name.'</a>';                                 
                        $source .="</li>";
                    }
                                   
            }
            
            $source .="</ul>";
            return $source;
    }    
}

Phase 3: Make Laravel 6 a view file

resources/views/treeview.blade.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Dynamic Treeview with jQuery, Laravel PHP Framework Example - tamilrokers free download source code</title>
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" />
    <link href="http://www.expertphp.in/css/bootstrap.css" rel="stylesheet">
    <link rel="stylesheet" href="http://demo.expertphp.in/css/jquery.treeview.css" />
    <script src="http://demo.expertphp.in/js/jquery.js"></script>   
    <script src="http://demo.expertphp.in/js/jquery-treeview.js"></script>
    <script type="text/javascript" src="http://demo.expertphp.in/js/demo.js"></script>
</head>
<body>
<div class="container">      
    {!! $tree !!}
</div> 
</body>
</html>

Web Programming Tutorials Example with Demo

Read :

Read Also:  Laravel 7 Guzzle Http Client Request Example

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about Laravel 6 tree view Plugins using jQuery Example.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.