AdminTW comes in a collection of helpers, located in app/Http/helpers.php
Abort when user does not have permission to perform the requestion action.
For instance abort users from seeing user activity when they don't have permissions from their given roles. The action is looked up as a boolean, it can be used inside if statements.
When the user does not have permission the message will be printed: You do not have permissions to (permission name)
The helper takes 2 arguments, the name to check and the status code. The default status code is 401.
abort_if_cannot(string $action, int $code = 401)
This performs the same as above but when a permission returns false instead of aborting globally an error view is returned, this is helpful if you want to show a message but don't stop the page execution.
abort_permission(string $action, int $code = 401)
Pass an array of data to populate the user log. This adds to the user activity table.
The following keys are supported:
- Title $data['title'] sets the activity title
- Link $data['link'] a URL link
- Reference identifier $data['id'] set a reference normally a model's primary key
- Section $data['section'] identifty the section ie Users, Posts
- Type $data['type'] sets the type of activity ie Create, Update, Delete
add_user_log([ 'title' => "updated ".$this->user->name."'s password", 'reference_id' => $this->user->id, 'link' => route('admin.users.edit', ['user' => $this->user->id]), 'section' => 'Users', 'type' => 'Update' ]);
This checks if a user has a given permission, returns a boolean.
Create an avator by providing a name, normally initials followed by the desired filename and location to be stored.
//generate image $name = get_initials($user->name); $id = $user->id.'.png'; $path = 'users/'; $imagePath = create_avatar($name, $id, $path); //save image $user->image = $imagePath; $user->save();
This checks if a user does not have a given permission, returns a boolean.
Return the first letter of each word.
Determine if a given item ($needle) is in an array of any of its childrens array. The lookup is recursive.
in_array_r($needle, $haystack, $strict = false)
This checks if a user has a role of admin, returns a boolean.
This checks if a user has a role, returns a boolean.
Return a user friendly size from a given bytes. In the format of B, kB, MB, GB, TB
Check if a $file exists inside Laravel's storage, by default the public disk will be used.
storage_exists($file, $disk = 'public')
Return a url from storage its the equivalent of Storage::url($file).
storage_url($file, $disk = 'public'):
Reuturns an instance of the users auth: auth()->user().
Return VAT by providing a price and VAT amount.
vat(float $price, int $vat)