2
Laravel Version: 5.26.27
Voyager Version: 1.1.3
PHP Version: 7.2.1
Database Driver & Version: MySQL 5.6.38
Description:

I'm new to Voyager but have already managed to create tables, populate them and configure their access privileges for BREAD.

But I need one option to see in the posts the custom roles can view just himself post, I see one option

@foreach($dataTypeContent->where('author_id','=', Auth::user()->id) as $data)

But this code modifies all views because is in the view. I need some more generic in the model

Is this possible with Voyager or it calls for custom code? Thanks in advance!

L_J
  • 2,223
  • 10
  • 19
  • 26
Jorge Iraira
  • 31
  • 1
  • 3

1 Answers1

1

Your question is a little confusing to read, but it sounds like you're asking if it's possible to override Voyager views or add custom views and the answer is, yes you can.

They have a video here: https://laravelvoyager.com/academy/views/

and written documentation here: https://voyager.readme.io/docs/overriding-views

The short of it is, create a directory resources/views/vendor/voyager/slug-name where slug-name is the slug for the corresponding table view you want to override. Put an edit-add.blade.php file in that folder along with a browse.blade.php file. I would just copy Voyagers default view logic into those files and then modify them to suit your needs.

WhyAyala
  • 516
  • 5
  • 26
  • What I try to do is: that in the post the administrator sees all the posts and that the writer or editor sees only the ones he wrote. it brings by default that certain role adds or edits all that are available – Jorge Iraira Aug 02 '18 at 17:14
  • 1
    @JorgeIraira You want the browse view to change depending on the role? Right? – WhyAyala Aug 02 '18 at 17:27
  • @JorgeIraira Well you are going to have to change Voyager's default code. To do that, you will have to do what I said in my answer. That will let you change Voyager's default. HOW you change Voyager's default is up to you. If you like I can add a suggestion on HOW you can do that in my answer, but I need to look up Voyager. It has been a long time since I used Voyager and I need to read. – WhyAyala Aug 02 '18 at 17:37
  • @JorgeIraira to be honest, i think you'd be better off checking the role of the user on the controller, and then sending the posts data that you want the user with that role to see. Make sense? – WhyAyala Aug 02 '18 at 18:29
  • i make the new bowser.blade.php and make a filter like Auth:User()->role_id == '1' if is admin to change only in the view if is the admin or other user, for admin @foreach($dataTypeContent as $data) and the others users @foreach($dataTypeContent->where('author_id','=', Auth::user()->id) as $data) for show only the him self post – Jorge Iraira Aug 02 '18 at 23:20
  • @JorgeIraira yes i believe that will work. I only recommend doing it on the controller instead because that's a lot of logic in the view and you could just filter the data going to the view before hand. Whatever works for you though. It sounds like you figured it out. – WhyAyala Aug 08 '18 at 20:32