While you follow along and encountred some errors as I did, I suggest you to make some amendments.
To seed position rows. Amend in CategoryFactory.php:
ublicfunctiondefinition():array
{
$country=fake()->unique()->country();
return [
'name'=>$country,
'slug'=>Str::slug($country),
'position'=>fake()->numberBetween(1, 10),
];
}
Import namespace in CategoriesList.php
use Illuminate\Support\Collection;
For better UX and Web accessibility aspect, change buton cursor class to cursor-move in categories-list.blade.php:
If an item will be positioned in another page than page 1, order number begins from 1. This causes that there are 2 categories with the same position number. The refactoring in CategoriesList helped me to achieve the problem.
Again so many issues following alone had to check the comments for fixes, and this comments were posted a month(s) ago not sure why the tutorial text was not updated. Not trying to be mean just giving honest feedback.
Why did you not use the variable $cat inside the if?
Why did you fetch Category::where...?
I assume there are some advantages but i can't figure it out.
It is used inside the if, but you might be confusing this because it looks like a database query.
The $cat variable comes from a collection, not the databse in this case (it's missing the categories()) and that makes it work with the data that is already loaded as a relationship.
hi dos the 'position' in categories table migration had to be nullable by default.it is showing error when i migrate:fresh and insert seed data
I think by default its value is 0, but can't guarantee: what is the actual error test and what seed data are you using?
I made the position default to 9999, so new Categories will be at the end. Or if you default to 0 it will be very first category
While you follow along and encountred some errors as I did, I suggest you to make some amendments. To seed position rows. Amend in
CategoryFactory.php:Import namespace in
CategoriesList.phpFor better UX and Web accessibility aspect, change buton cursor class to
cursor-moveincategories-list.blade.php:I've added the code to Category model. Position has same number as id on seeding or new creation of Category.
Where and how can we dump
$listarray to see what's inside?If we paginate 10 the $categories per page, how can we drag and drop 11 category to the first position?
You can dump where we update the order. So it would be
updateOrdermethod. To other page you cannot drag and drop.If an item will be positioned in another page than page 1, order number begins from 1. This causes that there are 2 categories with the same position number. The refactoring in CategoriesList helped me to achieve the problem.
Now how can you move a category that is on the second page to the first page? This seems to not be working.
Good question, I don't think it's possible with drag-drop. I guess it's better to build a separate button like "move one page up" or something.
Again so many issues following alone had to check the comments for fixes, and this comments were posted a month(s) ago not sure why the tutorial text was not updated. Not trying to be mean just giving honest feedback.
CategoryFactory position will increase in order.
Or you can increase the position value this way.
'position' => Category::max('position') + 1@Emre DikemYep, that's the approach i took too.Why did you not use the variable $cat inside the if? Why did you fetch Category::where...? I assume there are some advantages but i can't figure it out.
It is used inside the if, but you might be confusing this because it looks like a database query.
The $cat variable comes from a collection, not the databse in this case (it's missing the
categories()) and that makes it work with the data that is already loaded as a relationship.Thank you for your quick reply! Appreciate it, and the whole job you are doing here.
the position Is Not working at all I am not getting any arrers but at the same time it will not work eather
Not shour where you have the following code I just can not find it in the GutHub repository any help would be apreciated!
protected static function boot() { parent::boot();
}
Repository is in the last lesson: https://github.com/LaravelDaily/Laravel-Livewire-Orders Don't forget that this course uses Livewire v3, but you mentioned you use v4.