bradcornford / Googlmapper

An easy way to integrate Google Maps with Laravel
MIT License
464 stars 142 forks source link

Laravel 5.4 don't catch Exceptions #186

Closed majweb closed 7 years ago

majweb commented 7 years ago

Hi!

I use this package in laravel 5.4. In my controler i have: `try{ foreach($user->connected_to_gyms as $key =>$man){ Mapper::location("$man->city $man->street $man->local")->map(['zoom' => 15, 'center' => true, 'marker' => true, 'type' => 'roadmap']); } }catch(Exception $e){ return view...... }

@foreach($user->connected_to_gyms as $key =>$man)

{!! Mapper::render ($key) !!}
        @endforeach`

I'cant catch exceptions what is wrong?

bradcornford commented 7 years ago

Hi there,

Try the following:

try {
    foreach($user->connected_to_gyms as $key =>$man){
        Mapper::location("$man->city $man->street $man->local")->map(['zoom' => 15, 'center' => true, 'marker' => true, 'type' => 'roadmap']);
    }
} catch (\Exception $e) {
    return view......
}
majweb commented 7 years ago

Its works!

tell me how pass variables with errors to blade and use if and else element?

bradcornford commented 7 years ago

You should be able to return your view, with an error key, for example:

return view(...)->withErrors(['This is an error message']);