0

I want to make a custom edit-add view in Laravel Voyager: a row with two columns. In the 2nd column, I want to put a google map.

The questions are:

  • How should I filter if the field is a map?
  • When I get the map, how do I take the data from Voyager to render it?
Surf3r
  • 101
  • 1
  • 11

2 Answers2

1

I just found out how to do it! Here is the answer: In Voyager, every input you can use in the forms is already defined (also you can define custom inputs). In my case, I needed the coordinates form input, which shows a google map and lets you put a marker, saving latitude and longitude. This is how you include it in a custom form:

@php
   $dataTypeRows = $dataType->{(isset($dataTypeContent->id) ? 'editRows' : 'addRows' )};
   $row = $dataTypeRows->where('field', 'location')->first();
   $options = $row->details;
@endphp
@include('voyager::formfields.coordinates')

So what this all mean:

The first line ($dataTypeRows = $dataType->{(isset($dataTypeContent->id) ? 'editRows' : 'addRows' )};), basically tells if u are editing or adding (i.e., a new user).

In the second line ($row = $dataTypeRows->where('field', 'location')->first();), you get all the row data for "location" of the specific model. "location" is the name I've used in my case, there you must replace with the name you have set in your BREAD.

In the third line ($options = $row->details;), you get the details (custom json code you can put in each field in the BREAD).

Doing this, you only just set the data needed in the form field "coordinates", so you have to include the form field (google map) now. You do this in this final line: @include('voyager::formfields.coordinates').

Finally, with all the html, it could be like this:

    <div class="row">
        <div class="col-md-12">
            <div class="panel panel-bordered">
                <div class="panel-body">
                    <label for="location"> Ubicación </label>
                    @php
                        $dataTypeRows = $dataType->{(isset($dataTypeContent->id) ? 'editRows' : 'addRows' )};
                        $row = $dataTypeRows->where('field', 'location')->first();
                        $options = $row->details;
                    @endphp
                    @include('voyager::formfields.coordinates')
                </div>
            </div>
        </div>
    </div>

Custom coordinates form field

Surf3r
  • 101
  • 1
  • 11
0

I think not sure, you have to make separate folder in resources\views\vendor\voyager\

and copy from vendor\tcg\voyager\resources\views\bread\edit-add.blade.php to your new folder, this way when you call the edit view for this model you get you custom one, in your resources folder.

then you customize your action and add what you want to display in the blade, by adding to the model result as in

$model->mymap = $ created_map;

hope this helps