priority menu item
This commit is contained in:
@ -90,8 +90,6 @@ class MenuController extends AdminController
|
||||
*/
|
||||
public function actionEdit($id): void
|
||||
{
|
||||
// Debug::prn($_REQUEST);
|
||||
// Debug::prn($_FILES);
|
||||
$menuItem = Menu::find($id);
|
||||
if (!$menuItem){
|
||||
throw new Exception(message: "The menu item not found");
|
||||
|
@ -20,6 +20,7 @@ return new class extends Migration
|
||||
$table->string('url', 255);
|
||||
$table->string('slug', 255)->unique();
|
||||
$table->integer('status')->default(1);
|
||||
$table->integer('priority')->default(5);
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
@ -12,6 +12,7 @@ use Illuminate\Database\Eloquent\Model;
|
||||
* @property string label
|
||||
* @property string url
|
||||
* @property int status
|
||||
* @property int priority
|
||||
* @method static find($id)
|
||||
*/
|
||||
|
||||
@ -21,7 +22,7 @@ class Menu extends Model
|
||||
const ACTIVE_STATUS = 1;
|
||||
|
||||
protected $table = 'menu';
|
||||
protected $fillable = ['parent_id', 'icon_file', 'icon_font', 'label', 'url', 'status', 'slug'];
|
||||
protected $fillable = ['parent_id', 'icon_file', 'icon_font', 'label', 'url', 'status', 'slug', 'priority'];
|
||||
protected array $dates = ['deleted_at'];
|
||||
|
||||
public static function labels(): array
|
||||
@ -34,6 +35,7 @@ class Menu extends Model
|
||||
'url' => 'URL',
|
||||
'status' => 'Статус',
|
||||
'slug' => 'Slug',
|
||||
'priority' => 'Приоритет'
|
||||
];
|
||||
}
|
||||
|
||||
|
@ -11,6 +11,7 @@ use kernel\FormModel;
|
||||
* @property string $label
|
||||
* @property string $url
|
||||
* @property int $status
|
||||
* @property int priority
|
||||
* @property string $slug
|
||||
* @property string $parent_slug
|
||||
*/
|
||||
@ -26,7 +27,8 @@ class CreateMenuForm extends FormModel
|
||||
'url' => 'required|min-str-len:1',
|
||||
'status' => '',
|
||||
'slug' => 'required|min-str-len:1|max-str-len:50',
|
||||
'parent_slug' => ''
|
||||
'parent_slug' => '',
|
||||
'priority' => ''
|
||||
];
|
||||
}
|
||||
}
|
@ -21,6 +21,7 @@ class MenuService
|
||||
$model->url = $form_model->getItem('url');
|
||||
$model->status = $form_model->getItem('status') ?? 1;
|
||||
$model->slug = $form_model->getItem('slug');
|
||||
$model->priority = $form_model->getItem('priority') ?? 5;
|
||||
if ($model->save()){
|
||||
return $model;
|
||||
}
|
||||
@ -70,6 +71,7 @@ class MenuService
|
||||
$menuItem->url = $form_model->getItem('url');
|
||||
$menuItem->status = $form_model->getItem('status');
|
||||
$menuItem->slug = $form_model->getItem('slug');
|
||||
$menuItem->priority = $form_model->getItem('priority') ?? 5;
|
||||
if ($menuItem->save()){
|
||||
return $menuItem;
|
||||
}
|
||||
@ -90,7 +92,7 @@ class MenuService
|
||||
}
|
||||
public static function getChild(int $id)
|
||||
{
|
||||
$collection = Menu::where("parent_id", $id)->get();
|
||||
$collection = Menu::where("parent_id", $id)->get()->sortBy('priority');
|
||||
if (!$collection->isEmpty()){
|
||||
return $collection;
|
||||
}
|
||||
|
@ -4,9 +4,6 @@
|
||||
* @var int $page_number
|
||||
*/
|
||||
|
||||
//use app\tables\columns\menu\MenuDeleteActionColumn;
|
||||
//use app\tables\columns\menu\MenuEditActionColumn;
|
||||
//use app\tables\columns\menu\MenuViewActionColumn;
|
||||
use Itguild\EloquentTable\EloquentDataProvider;
|
||||
use Itguild\EloquentTable\ListEloquentTable;
|
||||
use kernel\IGTabel\btn\PrimaryBtn;
|
||||
|
@ -4,7 +4,6 @@
|
||||
* @var \Illuminate\Database\Eloquent\Collection $menu
|
||||
*/
|
||||
|
||||
use app\models\User;
|
||||
use Itguild\EloquentTable\ViewEloquentTable;
|
||||
use Itguild\EloquentTable\ViewJsonTableEloquentModel;
|
||||
use kernel\IGTabel\btn\DangerBtn;
|
||||
|
Reference in New Issue
Block a user