Controller Laravel?

0

How can I style an object in a array in 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

Perciso that looks like this:

    
asked by anonymous 10.09.2017 / 01:35

1 answer

1

Remember not to violate the principles of architecture standard to MVC.

Controller only coordinates the 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 through this array with the @foreach of the blade. >

Your index on the Controller looks like this:

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

In the view

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

Or, implement it any way you like.

Remember:

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

View only knows the data entry and exit .

Controller coordinates Model and View invoking methods, without knowing implementations.

    
24.12.2018 / 16:05