R
R
Rodion2018-06-18 19:34:15
Laravel
Rodion, 2018-06-18 19:34:15

How to exclude a specific group of users from a form?

There is a category of users "amateur photographer". There is a directory in which there are a lot of other categories, in the filter it is possible to select a category, and so I want to remove the user category "amateur" from the filter
1. In the filter form, categories are displayed like this

{!! Form::select('category_id', $categories->lists('name', 'slug')->prepend('..', ''), $category ? $category->slug : null, ['id' => 'category_id', 'class' => 'form-control js-change-fields']) !!}

I have no idea how to exclude the category I need from this form.
Question two. Let's suppose that it turned out to be excluded from the filter... But you can still go to the /fotolyubitel/ category
2. How to block access to the /fotolyubitel/ section for everyone?
Question 3. Each category of users, more precisely, all authorized (registered) on the site, has an additional menu in which:
1. My page - displays the profile page
2. My photo works - displays all uploaded works
3. Upload photo - page with uploading works
4. Balance - replenishment of the balance The
question is - how to restrict access to these sections to a certain category of users? And hide menu items for the same category.

Answer the question

In order to leave comments, you need to log in

4 answer(s)
Y
Yan-s, 2018-06-18
@Yan-s

1 - The question is not clear. You can remove a category from the database, you can filter at the level of a database query, remove it from a collection or an array. See what you need.
Points 2 and 3 - authorization. The doc is well described.

S
Sergey Gutovsky, 2018-06-18
@GutOf

$categories->filter(function ($category) {
    return $category->name != "фотолюбитель";
});

Returns all categories except "amateur photographer"

V
VitaliyBorys, 2018-06-19
@VitaliyBorys

For the first question, you have already been offered many options.
The second and third issue is solved by registering users.
Create a table user , role and role_user . The latter has a many-to-many relationship. One user in theory can have multiple roles. Describe a hasRole($role) method that will return true if the user has a $role group and false otherwise. And with that, you can close access to anything and anyone.

R
Rodion, 2018-06-19
@azmarin

Yan-s , In general, the first question was solved
3rd question solved:

@if(Auth::user()->category_id == 17)
не видно меню
@else
всем остальным видно
@endif

with the 2nd question:
how to close access to the section to everyone except the admin
and
how to close the category_id == 17 user group to certain sections
, I still don’t understand ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question