Users & Admins
Manage your users & admins directly from the Varbox admin panel, with no extra setup.
Admin Interface
Before going deeper, you should know that there's already a section in the admin from where you can manage all your users & admins.
Users Interface
You can find the users section inside Admin -> Access Control -> Users.
Feel free to explore all available options this section offers.
Admins Interface
You can find the admins section inside Admin -> Access Control -> Admins.
Feel free to explore all available options this section offers.
Addresses Interface
You can find the addresses section inside Admin -> Access Control -> Users -> Addresses.
Feel free to explore all available options this section offers.
Users & Admins
The users & admins component is a powerful access control functionality that allows you to quickly manage your users for your application.
In order to provide you with complex crud functionalities inside the admin, the users & admins cruds implement the following out of the box:
The
App\User
model now extends theVarbox\Models\User
class, for extra functionalities.
TheApp\User
model is bound to theuser_model
key insideconfig/varbox/bindings.php
Fetch Active / Inactive Users
You can get only active users by applying the onlyActive
query scope.
$users = \App\User::onlyActive()->get();
Alternatively, you can get only inactive users by applying the onlyInactive
query scope.
$users = \App\User::onlyInactive()->get();
Verify Active / Inactive User
You can verify if a user is active by applying the isActive
method.
$user = \App\User::find($id);
if ($user->isActive()) ...
Alternatively, you can verify if a user is inactive by applying the isInactive
method.
$user = \App\User::find($id);
if ($user->isInactive()) ...
Filter Admin Users
You can get only admin users by applying the onlyAdmins
query scope.
$admins = \App\User::onlyAdmins()->get();
Alternatively, you can get exclude admin users by applying the excludingAdmins
query scope.
$users = \App\User::excludingAdmins()->get();
Check Admin User
You can check if a user is an admin by applying the isAdmin
method.
$user = \App\User::find($id);
if ($user->isAdmin()) ...
User Addresses
Now that your App\User
model extends the Varbox\Models\User
model, it's also possible to assign addresses to your users.
You can also do this from inside the admin panel, when editing a user.
Fetch User Addresses
You can get a user's addresses by using the addresses
has many relation present on the Varbox\Traits\HasAddresses
trait.
$user = \App\User::find($id);
$addresses = $user->addresses;
Get Address User
You can get the belonging user of an address by using the user
belongs to relation present on the Varbox\Models\Address
model.
$address = \Varbox\Models\Address::find($id);
$user = $address->user;
Get Address Country
You can get the belonging country of an address by using the country
belongs to relation present on the Varbox\Models\Address
model.
$address = \Varbox\Models\Address::find($id);
$country = $address->country;
Get Address State
You can get the belonging state of an address by using the state
belongs to relation present on the Varbox\Models\Address
model.
$address = \Varbox\Models\Address::find($id);
$state = $address->state;
Get Address City
You can get the belonging city of an address by using the city
belongs to relation present on the Varbox\Models\Address
model.
$address = \Varbox\Models\Address::find($id);
$city = $address->city;
Filter Addresses By User
You can get only addresses belonging to a given user by using the ofUser
query scope present on the Varbox\Models\Address
model.
// by passing the user model
$addresses = \Varbox\Models\Address::ofUser($userModel)->get();
// or by passing the user id
$addresses = \Varbox\Models\Address::ofUser($userId)->get();
Filter Addresses By Country
You can get only addresses belonging to a given country by using the fromCountry
query scope present on the Varbox\Models\Address
model.
// by passing the country model
$addresses = \Varbox\Models\Address::fromCountry($countryModel)->get();
// or by passing the country id
$addresses = \Varbox\Models\Address::fromCountry($countryId)->get();
Filter Addresses By State
You can get only addresses belonging to a given state by using the fromState
query scope present on the Varbox\Models\Address
model.
// by passing the state model
$addresses = \Varbox\Models\Address::fromState($stateModel)->get();
// or by passing the state id
$addresses = \Varbox\Models\Address::fromState($stateId)->get();
Filter Addresses By City
You can get only addresses belonging to a given city by using the fromCity
query scope present on the Varbox\Models\Address
model.
// by passing the city model
$addresses = \Varbox\Models\Address::fromCity($cityModel)->get();
// or by passing the city id
$addresses = \Varbox\Models\Address::fromCity($cityId)->get();
Overwrite Bindings
In your projects, you may stumble upon the need to modify the behavior of these classes, in order to fit your needs.
Varbox makes this possible via the config/varbox/bindings.php
configuration file. In that file, you'll find every customizable class the platform uses.
For more information on how the class binding works, please refer to the Custom Bindings documentation section.
The classes available for binding overwrites are:
User Bindings
The user specific classes available for binding overwrites are:
Varbox\Models\User
Found in config/varbox/bindings.php
at models.user_model
key.
This class represents the user model.
Varbox\Controllers\UsersController
Found in config/varbox/bindings.php
at controllers.users_controller
key.
This class is used for interactions with the "Admin -> Access Control -> Users" section.
Varbox\Requests\UserRequest
Found in config/varbox/bindings.php
at form_requests.user_form_request
key.
This class is used for validating any user when creating or updating.
Varbox\Filters\UserFilter
Found in config/varbox/bindings.php
at filters.user_filter
key.
This class is used for applying the filtering logic.
Varbox\Sorts\UserSort
Found in config/varbox/bindings.php
at sorts.user_sort
key.
This class is used for applying the sorting logic.
Admin Bindings
The admin specific classes available for binding overwrites are:
Varbox\Controllers\AdminsController
Found in config/varbox/bindings.php
at controllers.admins_controller
key.
This class is used for interactions with the "Admin -> Access Control -> Admins" section.
Varbox\Requests\AdminRequest
Found in config/varbox/bindings.php
at form_requests.admin_form_request
key.
This class is used for validating any admin when creating or updating.
Varbox\Filters\AdminFilter
Found in config/varbox/bindings.php
at filters.admin_filter
key.
This class is used for applying the filtering logic.
Varbox\Sorts\AdminSort
Found in config/varbox/bindings.php
at sorts.admin_sort
key.
This class is used for applying the sorting logic.
Address Bindings
The address specific classes available for binding overwrites are:
Varbox\Models\Address
Found in config/varbox/bindings.php
at models.address_model
key.
This class represents the address model.
Varbox\Controllers\AddressesController
Found in config/varbox/bindings.php
at controllers.addresses_controller
key.
This class is used for interactions with the "Admin -> Access Control -> Users -> Addresses" section.
Varbox\Requests\AddressRequest
Found in config/varbox/bindings.php
at form_requests.address_form_request
key.
This class is used for validating any address when creating or updating.
Varbox\Filters\AddressFilter
Found in config/varbox/bindings.php
at filters.address_filter
key.
This class is used for applying the filtering logic.
Varbox\Sorts\AddressSort
Found in config/varbox/bindings.php
at sorts.address_sort
key.
This class is used for applying the sorting logic.