LarsWiegers / laravel-maps

Your laravel maps libary.
https://github.com/LarsWiegers/laravel-maps
MIT License
254 stars 35 forks source link

View Publishing #25

Closed ryangurn closed 2 years ago

ryangurn commented 2 years ago

I really love this package as it has made the process of displaying maps and coordinates super easy.

Thank you so much for putting in the time to build this!

I do have one request for improving the functionality. Currently on both map types you are essentially hardcoding in the height which is making it a bit more difficult to use with css frameworks such as bootstrap and tailwindcss.

This would be something that I could easily change if the views were published out in the same way that the config file is.

Would you consider changing uncommenting the following lines in LaravelMapsServiceProvider.php

...
// Publishing the views.
$this->publishes([
      __DIR__.'/../resources/views' => resource_path('views/vendor/maps'), // changed Laravel-maps to map since that is the value provided in loadViewsFrom
], 'views');
...

I have done a bit of digging in Laravel's package development documentation and noticed that when using $this->loadViewsFrom it will look in two places. The first of which is the views folder within the package and the second is the views/vendor folder within the resources directory.

When you use the loadViewsFrom method, Laravel actually registers two locations for your views: the application's resources/views/vendor directory and the directory you specify. So, using the courier package as an example, Laravel will first check if a custom version of the view has been placed in the resources/views/vendor/courier directory by the developer.

This would allow any other developers to make minor changes to the view without much effort.

Here is the documentation that I was reading by the way.

https://laravel.com/docs/9.x/packages#overriding-package-views

If you would like I can also test this and submit a PR if you would like, please just let me know in the comments on this issue and I can help as needed.

LarsWiegers commented 2 years ago

hi @ryangurn, awesome suggestion!

you can pass in a style or class attribute which will be used for the map, as seen here: https://github.com/LarsWiegers/laravel-maps/blob/master/resources/views/components/google.blade.php#:~:text=%3Cdiv%20id%3D%22%7B%7B%24mapId,%3E%3C/div%3E

let me know if that is not enough for your needs.

ryangurn commented 2 years ago

I have tried to pass style and it works but I want to customize it more than just the styles and its much easier when the views are published out to the resources/vendor/... directory.

ryangurn commented 2 years ago

@LarsWiegers are you open to publishing the views out?

LarsWiegers commented 2 years ago

I dont currently know enough about publishing views and what that would mean for future version of that file to say yes to this right now. I will have to do some research into it.

ryangurn commented 2 years ago

@LarsWiegers the link in my initial post to this thread acts as a good start. let me know if there is anything you need to understand view publishing!

LarsWiegers commented 2 years ago

i added a comment to the pr, if you change that I can merge it

ryangurn commented 2 years ago

thanks for merging it in!

LarsWiegers commented 2 years ago

@ryangurn thanks for the pr for it!