Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- public function createRank()
- {
- //A user wants to add a rank with the following permission id's
- $user_input_permissions = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 10, 10];
- $user_input_rank_name = "Customer Support";
- $canAddRank = true;
- //we ned to be sure all items are numbers and unique
- if(array_filter($user_input_permissions,'is_int')){
- $ids = array_unique($user_input_permissions);
- //we can check using NOT IN and array instead of lopp
- $permission = Permission::whereNotIn('id', $ids)->first();
- if($permission)
- {
- $canAddRank = false;
- break;
- }
- }
- if(!$canAddRank)
- return "Couldn't add rank. User tried to add a rank that didn't exist!";
- $rank = new CompanyRank;
- $rank->title = $user_input_rank_name;
- $rank->permissions = $user_input_permissions;
- $rank->save();
- return "Added Rank Successfully!";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement