I'm using the package: https://github.com/boxfrommars/rutorika-sortable To perform the
component
ordering of apage
, since I am not able to implement the ordering, the model has' traits` imported, as well as migrations.
With $id
: I get the component id.
With $model->order
: I get the order of it.
With $request->all();
: I get the parameter of the route that is the action to raise or lower the component.
public function beforeUpdate(Request $request, $id, $data) {
// ID do componente
$entity = $id;
// Order do Componente
$model = $this->getCurrentEntry();
$order = $model->order;
$entity->moveAfter($order);
// $post->tags()->moveBefore($entityToMove, $whereToMoveEntity);
// $post->tags()->moveAfter($entityToMove, $whereToMoveEntity);
// dd($request->all(), $this->getCurrentEntry());
// moveAfter();
// moveBefore();
return [];
}
// VIEW
<div class="list-group">
@foreach( $model->components as $value)
@php($selected = $components[$value->component])
<div class="form-group row">
<label class="col-sm-6 col-form-label">{{$value->order}} - {{ $selected->title }}</label>
<div class="col-sm-6">
<a href="{{ route('website.pages.components.order.update', [$site, $slug, $value->id, 'order' => 'up']) }}" class="fa fa-angle-double-up btn btn-primary btn-sm"></a>
<a href="{{ route('website.pages.components.order.update', [$site, $slug, $value->id, 'order' => 'down']) }}" class="fa fa-angle-double-down btn btn-primary btn-sm"></a>
<a href="{{ route('website.pages.components.edit', [$site, $slug, $value->id]) }}" class="btn btn-warning btn-sm">Editar</a>
<a href="" class="btn btn-danger btn-sm">Deletar</a>
</div>
</div>
@endforeach
<a class="btn btn-primary" href="{{ route('website.pages.components.create', [$site, $slug]) }}"> Adicionar Componente </a>