typicms / nestablecollection Goto Github PK
View Code? Open in Web Editor NEWA Laravel Package that extends Eloquent\Collection to handle nested items following adjacency list model.
License: MIT License
A Laravel Package that extends Eloquent\Collection to handle nested items following adjacency list model.
License: MIT License
Hello,
I'm trying to get a flattened list of a nestable collection. Though, I'm using the name
column.
I can't seem to be able to set that column:
return $this->model->orderBy('parent_id')->get()->listsFlattened(null, 0, [], 'name');
This returns: Cannot pass parameter 3 by reference
When I remove the reference from the 3rd parameter if the listsFlattened
method, I only get:
array:3 [▼
1 => "En Category"
6 => "Third Categoryyy"
3 => "Second Category"
]
But even them ->listsFlattened(null, 0, [], 'name')
isn't really nice. (lot's of empty parameters).
Though, the table structure is like so:
Category id 3 (Second Category
) should be under the first category.
So to summarise:
It might be better to have the $column
property as first parameter
public function listsFlattened($column = 'title', BaseCollection $collection = null, $level = 0, array &$flattened = [], $indentChars = ' ')
Why is the item #3
in the example above not indended ?
Thanks!
If the model is also a child of root, how can I get the children of current model? (including children of children too)
this one is not working for different primary key suppose my table has primay as pk_id and one table has primary key has id how can i dynamically set the primary key here
Was there a breaking change introduced recently ?
The ->nest()
is returning 0 items again. (items are ordered by parent_id, with no changed on this end.)
When running dd($this->items);
after line 60 ($this->items = array_values(array_except($this->items, $keysToDelete));
) I get an empty array.
Is there any way to use this library for this purpose?
What I want is something like \App\Department::find(12345)->orderBy('parent_id')->get()->nest()->listFlattened('name')
I'm using NestableTrait in my model. I want to use where to select some of the rows. My model is Category
Category::where('name', "Clothes");
works fine. But if I want to use it like this:
Category::where('name', 'LIKE', "%Clothes%");
it doesn't have any items in it.
When I use a raw query to get the columns it has some items in it:
collect(DB::select("SELECT * FROM
categoriesWHERE
name LIKE '%clothes%';"));
Any idea how I can fix this? I would have used the raw query but I want the model's relations as well, and it doesn't make any sense to add the relations by join
when I can simply use the model.
Category::orderBy('parent_id')->get()->nest()->setIndent('> ')->listsFlattened();
proc_open(): fork failed - Cannot allocate memory
This code is worked in laravel version below 6, but in 6 it's not working above error occur.
As of 1.1.2.
I get my menu items like this. There's a way to get the Menu items and append children to clean up this snippets below.
$menu = Menu::query()
->where('name', 'Main')->first();
$menu->items = MenuItem::orderBy('id')
->where('menu_id', '=', $menu->id)
->get()
->childrenName('children')
->nest();
return ResponseBuilder::success([
'menu' => $menu
]);
Menu
public function items()
{
return $this->hasMany(MenuItem::class, 'menu_id');
}
Rather than returning a list of items, allowing a custom name to be chosen would make it more readable and also able to work out the box with other packages.
$categories = Category::orderByRaw('-name ASC')
->get()
->nest()
->listsFlattened('name');
dd($categories);
proc_open(): fork failed - Cannot allocate memory
I am getting the following error while installing on laravel 10:
Problem 1
- Root composer.json requires typicms/nestablecollection ^2.0.1 -> satisfiable by typicms/nestablecollection[2.0.1].
- typicms/nestablecollection 2.0.1 requires illuminate/database ~9.0 -> found illuminate/database[v9.0.0-beta.1, ..., 9.x-dev] but these were not loaded, likely because it conflicts with another require.
Debian 8
Mysql 8
Php 7.1.x
Thanks for sharing this project...
Have an issue after fresh install pretty much any creation activity such as creating a folder or uploading an image produces this type of error..
SQLSTATE[42S22]: Column not found: 1054 Unknown column '/admin/blocks' OR '/admin/files'
Pointers would be much appreciated..
Thanks
////// Create folder ////
[2018-09-24 19:20:48] local.ERROR: SQLSTATE[42S22]: Column not found: 1054 Unknown column '/admin/files' in 'field list' (SQL: insert into typicms_files
(folder_id
, type
, name
, description
, alt_attribute
, /admin/files
, updated_at
, created_at
) values (, f, dertui, [], [], , 2018-09-24 19:20:48, 2018-09-24 19:20:48)) {"userId":1,"email":"[email protected]","exception":"[object] (Illuminate\Database\QueryException(code: 42S22): SQLSTATE[42S22]: Column not found: 1054 Unknown column '/admin/files' in 'field list' (SQL: insert into typicms_files
(folder_id
, type
, name
, description
, alt_attribute
, /admin/files
, updated_at
, created_at
) values (, f, dertui, [], [], , 2018-09-24 19:20:48, 2018-09-24 19:20:48)) at /var/www/mysk/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664, PDOException(code: 42S22): SQLSTATE[42S22]: Column not found: 1054 Unknown column '/admin/files' in 'field list' at /var/www/mysk/vendor/laravel/framework/src/Illuminate/Database/Connection.php:452)
[stacktrace]
/////// create block /////
SQLSTATE[42S22]: Column not found: 1054 Unknown column '/admin/blocks' in 'field list' (SQL: insert into typicms_blocks
(name
, status
, body
, /admin/blocks
, updated_at
, created_at
) values (Nonka, {"fr":"0","nl":"0","en":"0"}, {"fr":null,"nl":null,"en":"
Slop</p>"}, , 2018-09-24 19:27:13, 2018-09-24 19:27:13))
Hi, unable to install via composer in laravel 9. Please edit composer.json
I have extended NestableCollection in my application, but I can't access the internal variables in NestableCollection from my extended class because they're private. Could you please make them protected instead so I can use them?
Method Illuminate\Database\Eloquent\Collection::nest does not exist.
This is the error shown in whoops. I followed the instructions and still i get this error.
I have added the trait in the model still it doesnt work.
<?php
namespace App;
use TypiCMS\NestableTrait;
use Illuminate\Database\Eloquent\Model;
class Permission extends Model
{
protected $fillable = [
'id',
'parent_id',
'permission_name',
'show_name',
];
}
I'm using Laravel 5.6.
The query I called is
return $permissions =Permission::orderBy('parent_id')->get()->nest();
Can you please solve this issue?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.