Laravel Controller?

Asked

Viewed 69 times

0

How I can style an object into one array in the controller Laravel?

Mapper::marker($marker['lat'], 
          $marker['lng'],['label'=> "<div>".$marker['label']."</div>"]);

Controller

public function index(){

  Mapper::map(-22.886449, -43.118474,
      [   'marker'=>false,
          'zoom' => 10,
          'draggable' => true,
          'center' => true,
          'cluster' => false,
          'markers' => [
          'eventBeforeLoad' => 'addMapStyling(map);',
          'icon' =>'img/ida_22.png',
          'title' => '166001',
          'animation' => 'DROP'],
      ]);

      $markers = array(['lat' => -22.886449,'lng' => -43.118474,'label'=> 'Veículo 01'],
                       ['lat' => -22.885632,'lng' => -43.118143,'label'=> 'Veículo 02'],
                       ['lat' => -22.883990,'lng' => -43.119513,'label'=> 'Veículo 03'],
                       ['lat' => -22.885734,'lng' => -43.124988,'label'=> 'Veículo 04']);

      foreach ($markers as $marker) {
            //dd($marker['label']);
            Mapper::marker($marker['lat'], $marker['lng'],
                          ['label'=> $marker['label']]);

           Mapper::informationWindow($marker['lat'], $marker['lng'], $marker['label']);
      }

    return view('rastreamento.mapa.mapa');
}

View

<div id="#map-canvas-0">
    {!! Mapper::render() !!}
</div>

The package name and cornford googlmapper

I need it to stay that way:

inserir a descrição da imagem aqui

  • You configure the style in the View and Controller only send data!? got it

  • I am using that package of cornford google mapper, which facilitates integration with google map, put all the logic in the controller, in the view there is only one variable rendered and the controller is like the example below: foreach ($markers as $Marker) { Mapper::Marker($Marker['lat'], $Marker['lng'],['label'=> $Marker['label']]); Mapper::informationWindow($Marker['lat'], $Marker['lng'], $Marker['label']); }

  • Put the package name, put all the code, put an example of how it looks and how you want it to look like ... !!! is little information.

1 answer

1

Remember not to hurt the principles of architectural patternthe MVC.

Controller only coordinates communication between Model and View. It should not know implementations and should not contain business rules.

Example:

You could create a method in your model with the entire map implementation, return as an array, call the model method in the controller, pass it to view, and iterate this array with the Blade @foreach.

Your index in Controller would look like this:

public function index()
{
    return view('caminho.nome.da.view', ['mappeds' => Mapper::mappedItems()]);
}

In view

@forelse($mappeds as $mapped)
{{ $mapped->value }}
@else
<p>Nenhum resultado encontrado</p>
@endforelse

Or, implement the way you wish.

Remember:

Model only he knows business rule implementations, validation, verification and etc..

View only knows the data input and output.

Controller co-ordinates the Model and the View invoking methods, unknowingly its implementations.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.