A
A
AntoxaVolkov2017-03-12 21:14:51
Laravel
AntoxaVolkov, 2017-03-12 21:14:51

How to add and remove categories in franzose/ClosureTable for Laravel?

Good day!
How to add and remove categories (records) in franzose/ClosureTable for Laravel?
addChild() is when an entry is selected. And if the database does not yet have more than one record, then how to add a new one?
new Model(array(...))->save();- writes to the database, but phpMyAdmin starts to swear when fetching, gives a bunch of errors and the question is whether to ignore them or not.
60119fb12054475588a0e90c3963c2bd.png
SQL query
07c37d5544e647428c651d7628fc3648.png

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Mokhirjon Naimov, 2017-03-13
@zvermafia

And if the database does not yet have more than one record, then how to add a new one?

$category = new Category([
    'title' => 'News'
]);

$category->makeRoot(0);

UPD: Try this
$category = new Category;
$category->title = 'News';
$category->save();

PS I have used the 1st or 2nd option in some projects. So both options work for me!

A
andreyGot, 2018-05-22
@andreyGot

is there a step by step guide somewhere for using franzose/ClosureTable for beginners? Apart from the docs on gitHub. To show an example of a controller, model, migration?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question