AmmoLand Giveaway – 5,000 Rounds of CCI Blazer 9mm Ammo FREE!

https://www.ammoland.com/wp-content/uploads/2021/04/ximsqwjcxky-500×281.jpg

U.S.A.-(AmmoLand.com)- New and existing subscribers to the AmmoLand News emails will ALL be eligible to win 5,000 rounds of CCI Blazer 9mm Ammo! At a time when ammo is nearly impossible to find, AmmoLand has decided to help one lucky winner with this giveaway of 5,000 rounds of CCI Blazer 9mm ammunition.

AmmoLand is giving our readers yet another opportunity to take home an amazing giveaway, this time it’s 5,000 rounds of 9mm ammo. One lucky winner will receive 5 boxes of 1000 rounds each, boxed 50 rounds per box in the 1000 round case.

AmmoLand Giveaway - 5,000 Rounds of CCI Blazer 9mm Ammo
AmmoLand Giveaway – 5,000 Rounds of CCI Blazer 9mm Ammo

CCI BLAZER BRASS 9MM LUGER AMMO 115 GRAIN FULL METAL JACKET

CCI Blazer Brass 9mm Luger Ammo 115 Grain Full Metal Jacket ammo made by CCI is your best choice for bulk 9mm target shooing ammunition. Newly manufactured 9mm ammo here in the United States, that features a full metal jacket copper plated bullet, brass casing, non-corrosive primers. Made by the same company that manufactures Speer Lawman 9mm ammo as well as the Federal American Eagle 9mm ammunition Blazer Brass 9mm Luger ammo features the same great quality components and manufacturing equipment. If you choose to reload your 9mm ammo, CCI Blazer Brass offers virgin brass that can be reloaded up to 5 times due to its exceptional high quality and low mixtures of other materials. Trusted CCI has gone above and beyond with the Blazer Brass line! With the same high standards that shooters have come to know and love with standard Blazer ammo, the Blazer Brass line gives the benefit of a brass casing making it reloadable. 9mm Luger by CCI are an excellent choice for target practice or just plinking around at the range. CCI Blazer Brass 9mm Luger is new production, non-corrosive, re-loadable ammunition with boxer primers and brass casing.

9mm ammo is by far the most popular gun cartridge in the world. Recently adopted by the FBI and other law enforcement agencies, 9mm ammunition is perfect for target shooting and personal protection as well. 9mm ammo is fun to shoot, offers relatively low recoil and yields great target results.

CCI Blazer Brass 9mm Luger is new production, non-corrosive, re-loadable ammunition with boxer primers and brass casing.

Blazer Brass 9mm ammunition is perfect for target shooting and personal protection as well.

  • Manufacturer – CCI AMMUNITION
  • Caliber – 9MM LUGER
  • Bullet Type – Full Metal Jacket
  • Muzzle Velocity – 1125 fps
  • Muzzle Energy – 323 ft lbs
  • Primer – Boxer
  • Casing – Brass Casing
  • Ammo Rating – Target and Practice 9mm Ammo

How to Win 5,000 Rounds of 9mm:

  • Click the AmmoLand Giveaway button on the bottom right of any AmmoLand.com page
  • Click Subscribe to Our Newsletter for one entry, existing subscribers you are already in the running, who loves you?
  • Click Visit AmmoLandTV on YouTube and like and follow for another entry
  • Click Visit @AmmoLand on Instagram and like and follow for a third entry

AmmoLand Giveaway Rules:

  • The giveaway entry dates run from May 25th, 2021 to July 1st, 2021 with the winner drawn on July 2nd, 2021.
  • Everyone who signs up, or is an existing active subscriber, to the AmmoLand Shooting Sports News daily digest email are eligible to win.
  • Eligible Winners must be 18 years of age, a legal resident of the United States, and be lawfully eligible under local, state, and federal rules to accept the transfer of Firearms through a licensed Federal Firearms Licensee. NOTE: All Federal, State and Local gun magazine restrictions apply. You can view a sample of typical restrictions here or here
  • FFL Transfer Fees and Taxes are not included and are the winners’ responsibility.
  • No monetary compensation or substitution for ineligible winners.
  • Do you get our daily email? Then you are already entered. Do you need to sign up? Then you can do so at the link/box above: Sign up for AmmoLand in your Inbox!

What’s that you say? You never win anything or maybe 5000 is not enough ammo and you need more, then check out our 9mm Deal Tracker page page found here!


About AmmoLand.com:

Ammoland.com is the web’s leading Shooting Sports News Service for the Ammunition, Firearms, Shooting, Hunting, and Conservation communities. AmmoLand has a FREE Shooting Sports News Service that is seen by 10,000’s of Ammunition, Shooting, and Pro Firearms enthusiasts every day. Visit them at www.AmmoLand.com

Ammoland Logo Schema

Don’t delay! Be sure and Sign Up before we pick a winner.

The post AmmoLand Giveaway – 5,000 Rounds of CCI Blazer 9mm Ammo FREE! appeared first on AmmoLand.com.

AmmoLand.com

A configuration that can double MySQL write performance

https://mysqlonarm.github.io/images/blog21/img1.png

MySQL is heavily tunable and some of the configuration can have significant impact on its performance. During my experiment for numa scalability I encountered one such configuration. Default configuration tends to suggest heavy contention for write workload but once tuned it helps scale MySQL by more than 2x.

Understanding the problem

I started testing write-workloads with different numa levels (1 numa [32 cores]/2 numa [64 cores]/ 4 numa [128 cores]) and observed a weird behavior.

  • With increasing compute power we expected throughput to grow. The pattern is observed when we move from 1 numa to 2 numa but there is significant throughput loss (despite double compute power) when switched from 2 numa to 4 numa.
  • This is exactly what we call as NUMA SCALABILITY BOTTLENECK (vs a SCALABILITY BOTTLENECK that tends to achieve optimal performance with a given set of compute and io resources).

server: mysql-8.0.24.
configuration: click here (+ skip-log-bin)
machine: ARM machine (kunpeng 920 (2 sockets, 128 cores, 4 numa nodes), nvme ssd)
workload: sysbench update-index (cpu-bound)

Identifying the bottleneck

To get more insight on contention I resorted to perf-schema.

+-----------------------------------------------+---------------+------------+
| EVENT_NAME                                    | WAIT_MS       | COUNT_STAR |
+-----------------------------------------------+---------------+------------+
| wait/synch/mutex/innodb/trx_sys_mutex         | 28341923.1285 |    8637971 |
| wait/synch/mutex/innodb/undo_space_rseg_mutex | 24417716.9238 |    3895877 |
| wait/synch/mutex/innodb/sync_array_mutex      |  3619893.6460 |   38717477 |
+-----------------------------------------------+---------------+------------+
3 rows in set (0.05 sec)

Surprisingly the 2nd most contended mutex is rollback segment mutex. (1st being trx_sys that is a known issue and mysql hopefully is working on it to make trx_sys lock-free).

Fortunately, there is a way out.

undo tablespaces

MySQL has been working on improving the undo tablespace framework for quite some time, starting with undo tablespace truncation (and I am fortunate enough to code it back in 5.7x timeframe). I still remember discussing the limitation of the 128 rollback segments but given it would need major change it was deferred to 8.x and eventually it came with 8.x (changes around 8.0.14 and then again 8.0.23) where-in user can now configure extra undo tablespaces and that in turn defines number of rollback segments.

Here is the latest and simplified view:

InnoDB will create 2 default undo tablespaces (also known as implicit tablespaces)
Users can add 125 (maximum) undo tablespaces (also known as explicit tablespaces).
Total: 127 undo tablespaces.

Each undo tablespace can host 128 rollback segments (controlled using innodb_rollback_segments).

So 127 * 128 = 16256 rollback segments are available for transactions.

mysql> show status like '%undo%';
+----------------------------------+-------+
| Variable_name                    | Value |
+----------------------------------+-------+
| Innodb_undo_tablespaces_total    | 127   |
| Innodb_undo_tablespaces_implicit | 2     |
| Innodb_undo_tablespaces_explicit | 125   |
| Innodb_undo_tablespaces_active   | 127   |
+----------------------------------+-------+
4 rows in set (0.00 sec)

(It is just 128 rollback segments in 5.7. Starting 8.x given 2 default undo tablespaces 256 rollback segments are made active by default)

Resolving Contention

So with default 2 undo-tablespaces only 256 rollback segments are made active and N transactions will share these rollback segments. With N = 150K approximately 586 transactions use the same rollback segments creating heavy contention as all of them need the said mutex latch in order to add their undo-logs to transaction history during commit stage (check trx_write_serialisation_history for more details).

If we create additional 125 explicit undo tablespaces it would make 127 * 128 = 16256 rollback segments that is around 9 transactions per rollback segment significantly reducing the contention.

Let’s see if this solution helps.

Same could be confirmed with perf schema output

With 2 undo tablespaces:

+-----------------------------------------------+---------------+------------+
| EVENT_NAME                                    | WAIT_MS       | COUNT_STAR |
+-----------------------------------------------+---------------+------------+
| wait/synch/mutex/innodb/trx_sys_mutex         | 88168453.5988 |   19540096 |
| wait/synch/mutex/innodb/undo_space_rseg_mutex | 78933376.9118 |   14811159 |
| wait/synch/mutex/innodb/sync_array_mutex      | 11274812.8370 |  111143905 |
+-----------------------------------------------+---------------+------------+
3 rows in set (0.04 sec)

With 127 undo tablespaces:

+-------------------------------------------------+----------------+------------+
| EVENT_NAME                                      | WAIT_MS        | COUNT_STAR |
+-------------------------------------------------+----------------+------------+
| wait/synch/mutex/innodb/trx_sys_mutex           | 153155037.4916 |   33537120 |
| wait/synch/mutex/innodb/buf_pool_LRU_list_mutex |  18706130.3456 |   38819242 |
| wait/synch/mutex/innodb/sync_array_mutex        |   4240650.4708 |   93054607 |
+-------------------------------------------------+----------------+------------+
3 rows in set (0.08 sec)

| wait/synch/mutex/innodb/undo_space_rseg_mutex           |    213977.8787 |   31464777 |

Wait has reduced from 78933376 milli-seconds (77 seconds per thread) to 213977 milli-seconds (0.2 seconds per thread).

Fallback (if any?)

Approach of increasing undo tablespace is really good but enabling 125 explicit tablespaces consumes disk space and to keep this in limit users should configure undo tablespace truncate.

Default innodb_max_undo_log_size = 1GB assuming all 127 tablespaces are growing uniformly, truncate will not kick in till all of them are around 1GB in size there-by consuming 127GB of the disk space.

If you plan to enable 127 tablespaces then better is to reduce the innodb_max_undo_log_size (unless disk space is not a concern).

Effect of enabling 127 tablespaces on lesser numa nodes

As we could see there is negligible/marginal effect on enabling 127 tablespaces for lower numa nodes. NUMA scalability fix/solution effects are observed with increased numa nodes but minimal change is observed for lower numa nodes. We can have a separate blog post about NUMA scalability explaining why such effects are observed.

Conclusion

Scaling MySQL for NUMA has its own challenges and while the solution for some of these problems pre-exist extra configuration may be needed. It would be really helpful if MySQL can auto detect and configure some of these limits based on the numa configuration it is running on.

If you have more questions/queries do let me know. Will try to answer them.

Planet MySQL

Ford Designs Simple Anti-COVID DIY Air Filtration with Common Box Fan

https://s3files.core77.com/blog/images/1185521_81_108828_LPsS3rIgM.jpg

Now that we know COVID is spread via aerosol rather than fomites, having clean air is of more concern than clean hands. Automaker Ford, working together with fan manufacturer Lasko, is addressing this with their design of a simple air filtration system centered on a common box fan.

The design stemmed from research conducted "using supercomputer air flow analysis to determine if a low-cost box fan air cleaner can mitigate the risk of airborne transmission of COVID-19 in a classroom equipped with a single horizontal unit ventilator."

"The study found that box fan air cleaners like this can serve as an effective low-cost alternative for mitigating airborne transmission risks in poorly ventilated spaces."

Ford and Lasko’s inexpensive fix is simply a cardboard cutout that supports an ordinary air filter (they’re recommending MERV 13 or higher, so it looks like you don’t have to go full HEPA) and attaches to a box fan.

They’re calling it the Scrappy Filtration system, and they’ve donated 20,000 kits to schools in underserved communities.

If you want to make your own, they’ve got a template you can download here.

Core77

Laravel 8 Roles and Permissions Without Package

https://www.codecheef.org/user/img/fevicon.png

Laravel 8 Roles and Permissions Without Package

Posted By


Mahedi Hasan

Category

Framework

Sub-category

Laravel 5.6

November 14, 2019

Roles and permissions are an important part of many web applications. In this tutorial we will see how we can implement user roles and permissions system in laravel. We will see it from scratch. We won’t use /laravel-permission package for doing it. But you can use /laravel-permission to create this roles and permissions system in laravel 8.

It is important to add laravel user roles and permissions mechanism in our large scale application to give the permit to user to specific task. We will see from scratch laravel 8 user roles and permissions tutorial. 

If you don’t know how to create laravel 8 roles and permissions, then you are a right place. I will teach you from scratch laravel roles and permissions.But in this tutorial we will do user roles and permissions in laravel using our own custom code. So let’s start how to implement & setup roles and permissions in Laravel.

I updated this tutorial for laravel 8 version. So if you face any error, then you can check git repository. Let’s start laravel 8 user roles and permissions tutorial.

 

Git Repository : User Roles & Access Permission Laravel 

 

roles-permissions-laravel

 

Step 1 : Download Laravel Project

Open up your terminal and create a new Laravel project by typing in the following command

composer create-project --prefer-dist laravel/laravel blog

 

Step 2:  Make Auth

If you are using laravel version 6 then run below command to make auth

composer require laravel/ui --dev
php artisan ui vue --auth
npm install
npm run watch

 

If you are using below laravel version 6 then run below command to make auth

php artisan make:auth

 

Step 3 : Make Model

We need model to make users roles and permissions. So let’s create our model using below command.

php artisan make:model Permission -m
php artisan make:model Role -m

 

As you may know, -m flag will create a migration file for the model. Now you’ll have two new migration files waiting for you to add new fields. 

 

Step 4 : Edit the migration file

 

public function up()
    {
       Schema::create('users', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name');
            $table->string('email',191)->unique();
            $table->timestamp('email_verified_at')->nullable();
            $table->string('password');
            $table->rememberToken();
            $table->timestamps();
    });
}

 

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreatePermissionsTable extends Migration
{
    
    public function up()
    {
        Schema::create('permissions', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name'); // edit posts
            $table->string('slug'); //edit-posts
            $table->timestamps();
        });
    }

    public function down()
    {
        Schema::dropIfExists('permissions');
    }
}

 

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateRolesTable extends Migration
{
    public function up()
    {
        Schema::create('roles', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name'); // edit posts
            $table->string('slug'); //edit-posts
            $table->timestamps();
        });
    }

    public function down()
    {
        Schema::dropIfExists('roles');
    }
}

 

Step 5 : Adding pivot tables

For this first pivot table, we’ll create a new migration file for the table users_permissions. So run below command to create

php artisan make:migration create_users_permissions_table --create=users_permissions

 

For this pivot table between users and permissions, our schema should look like

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateUsersPermissionsTable extends Migration
{
    public function up()
    {
        Schema::create('users_permissions', function (Blueprint $table) {
            $table->unsignedInteger('user_id');
            $table->unsignedInteger('permission_id');

            //FOREIGN KEY CONSTRAINTS
            $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
            $table->foreign('permission_id')->references('id')->on('permissions')->onDelete('cascade');
 
            //SETTING THE PRIMARY KEYS
            $table->primary(['user_id','permission_id']);
        });
    }

    public function down()
    {
        Schema::dropIfExists('users_permissions');
    }
}

 

Now let’s create a pivot table for users_roles.

php artisan make:migration create_users_roles_table --create=users_roles

 

The fields inside this table will pretty much the same as in users_permissions table. Our schema for this table will look like:

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateUsersRolesTable extends Migration
{
    public function up()
    {
        Schema::create('users_roles', function (Blueprint $table) {
            $table->unsignedInteger('user_id');
            $table->unsignedInteger('role_id');

         //FOREIGN KEY CONSTRAINTS
           $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
           $table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');

         //SETTING THE PRIMARY KEYS
           $table->primary(['user_id','role_id']);
        });
    }

    public function down()
    {
        Schema::dropIfExists('users_roles');
    }
}

 

Under a particular Role, User may have specific Permission

For example, a user may have the permission for post a topic, and an admin may have the permission to edit or delete a topic. In this case, let’s setup a new table for roles_permissions to handle this complexity.

 

php artisan make:migration create_roles_permissions_table --create=roles_permissions

 

The Schema will be like:

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateRolesPermissionsTable extends Migration
{
    public function up()
    {
        Schema::create('roles_permissions', function (Blueprint $table) {
             $table->unsignedInteger('role_id');
             $table->unsignedInteger('permission_id');

             //FOREIGN KEY CONSTRAINTS
             $table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');
             $table->foreign('permission_id')->references('id')->on('permissions')->onDelete('cascade');

             //SETTING THE PRIMARY KEYS
             $table->primary(['role_id','permission_id']);
        });
    }

    public function down()
    {
        Schema::dropIfExists('roles_permissions');
    }
}

 

Now run following command to create migration

php artisan migrate

 

Step 6 : Setting up the relationships

We’ll start by creating the relationships between roles and permissions table. In our Role.php , Permision.php.

App/Role.php

public function permissions() {

   return $this->belongsToMany(Permission::class,'roles_permissions');
       
}

public function users() {

   return $this->belongsToMany(User::class,'users_roles');
       
}

 

App/Permission.php

public function roles() {

   return $this->belongsToMany(Role::class,'roles_permissions');
       
}

public function users() {

   return $this->belongsToMany(User::class,'users_permissions');
       
}

 

Step 7 : Creating a Trait

Inside of our app directory, let’s create a new directory and name it as Permissions and create a new file namely HasPermissionsTrait.php. A nice little trait has been setup to handle user relations. Back in our User model, just import this trait and we’re good to go.

app/User.php

namespace App;

use App\Permissions\HasPermissionsTrait;

class User extends Authenticatable
{
    use HasPermissionsTrait; //Import The Trait
}

 

Now open HasPermissionsTrait.php and paste those following code.

App/Permissions/HasPermissionsTrait.php

namespace App\Permissions;

use App\Permission;
use App\Role;

trait HasPermissionsTrait {

   public function givePermissionsTo(... $permissions) {

    $permissions = $this->getAllPermissions($permissions);
    dd($permissions);
    if($permissions === null) {
      return $this;
    }
    $this->permissions()->saveMany($permissions);
    return $this;
  }

  public function withdrawPermissionsTo( ... $permissions ) {

    $permissions = $this->getAllPermissions($permissions);
    $this->permissions()->detach($permissions);
    return $this;

  }

  public function refreshPermissions( ... $permissions ) {

    $this->permissions()->detach();
    return $this->givePermissionsTo($permissions);
  }

  public function hasPermissionTo($permission) {

    return $this->hasPermissionThroughRole($permission) || $this->hasPermission($permission);
  }

  public function hasPermissionThroughRole($permission) {

    foreach ($permission->roles as $role){
      if($this->roles->contains($role)) {
        return true;
      }
    }
    return false;
  }

  public function hasRole( ... $roles ) {

    foreach ($roles as $role) {
      if ($this->roles->contains('slug', $role)) {
        return true;
      }
    }
    return false;
  }

  public function roles() {

    return $this->belongsToMany(Role::class,'users_roles');

  }
  public function permissions() {

    return $this->belongsToMany(Permission::class,'users_permissions');

  }
  protected function hasPermission($permission) {

    return (bool) $this->permissions->where('slug', $permission->slug)->count();
  }

  protected function getAllPermissions(array $permissions) {

    return Permission::whereIn('slug',$permissions)->get();
    
  }

}

 

Here, we’re iterating through the roles and checking by the slug field, if that specific role exists. You can check or debug this by using:

$user = $request->user(); //getting the current logged in user
dd($user->hasRole('admin','editor')); // and so on

 

Step 8 :  Create CustomProvider

We’ll be utilizing the Laravel’s “can” directive to check if the User have Permission. and instead of using $user->hasPermissionTo().

we’ll use $user->can() To do so, we need to create a new PermissionsServiceProvider for authorization

php artisan make:provider PermissionsServiceProvider

 

Register your service provider and head over to the boot method to provide us a Gateway to use can() method.

namespace App\Providers;

use App\Permission;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\ServiceProvider;

class PermissionsServiceProvider extends ServiceProvider
{
   
    public function register()
    {
        //
    }

    public function boot()
    {
        try {
            Permission::get()->map(function ($permission) {
                Gate::define($permission->slug, function ($user) use ($permission) {
                    return $user->hasPermissionTo($permission);
                });
            });
        } catch (\Exception $e) {
            report($e);
            return false;
        }

        //Blade directives
        Blade::directive('role', function ($role) {
             return "if(auth()->check() && auth()->user()->hasRole({$role})) :"; //return this if statement inside php tag
        });

        Blade::directive('endrole', function ($role) {
             return "endif;"; //return this endif statement inside php tag
        });

    }
}

 

now we have to register our PermissionsServiceProvider. Open this following file add this in providers array.

config\app.php

 'providers' => [

        App\Providers\PermissionsServiceProvider::class,
    
 ],

 

You can learn more about Laravel’s Gate facade at Laravel’s documentation. You can test it out as:

dd($user->can('permission-slug'));

 

Read also :  Laravel 6 Authorization using Gates

 

Step 9 : Add Dummy Data To Check

For creating roles and permissions tutorial, we need dummy data to check our user access. To create it paste this following code into this followng slug.

Route::get('/roles', 'PermissionController@Permission');

 

App\Http\Controllers\PermissionController.php

namespace App\Http\Controllers;

use App\Permission;
use App\Role;
use App\User;
use Illuminate\Http\Request;

class PermissionController extends Controller
{   

    public function Permission()
    {   
    	$dev_permission = Permission::where('slug','create-tasks')->first();
		$manager_permission = Permission::where('slug', 'edit-users')->first();

		//RoleTableSeeder.php
		$dev_role = new Role();
		$dev_role->slug = 'developer';
		$dev_role->name = 'Front-end Developer';
		$dev_role->save();
		$dev_role->permissions()->attach($dev_permission);

		$manager_role = new Role();
		$manager_role->slug = 'manager';
		$manager_role->name = 'Assistant Manager';
		$manager_role->save();
		$manager_role->permissions()->attach($manager_permission);

		$dev_role = Role::where('slug','developer')->first();
		$manager_role = Role::where('slug', 'manager')->first();

		$createTasks = new Permission();
		$createTasks->slug = 'create-tasks';
		$createTasks->name = 'Create Tasks';
		$createTasks->save();
		$createTasks->roles()->attach($dev_role);

		$editUsers = new Permission();
		$editUsers->slug = 'edit-users';
		$editUsers->name = 'Edit Users';
		$editUsers->save();
		$editUsers->roles()->attach($manager_role);

		$dev_role = Role::where('slug','developer')->first();
		$manager_role = Role::where('slug', 'manager')->first();
		$dev_perm = Permission::where('slug','create-tasks')->first();
		$manager_perm = Permission::where('slug','edit-users')->first();

		$developer = new User();
		$developer->name = 'Mahedi Hasan';
		$developer->email = 'mahedi@gmail.com';
		$developer->password = bcrypt('secrettt');
		$developer->save();
		$developer->roles()->attach($dev_role);
		$developer->permissions()->attach($dev_perm);

		$manager = new User();
		$manager->name = 'Hafizul Islam';
		$manager->email = 'hafiz@gmail.com';
		$manager->password = bcrypt('secrettt');
		$manager->save();
		$manager->roles()->attach($manager_role);
		$manager->permissions()->attach($manager_perm);

		
		return redirect()->back();
    }
}

 

Now goto this url and hit enter on your keyboard. Then you will see some dummy data to those following tables. To test this out in your routes files, we can die and dump on:

$user = $request->user();
dd($user->hasRole('developer')); //will return true, if user has role
dd($user->givePermissionsTo('create-tasks'));// will return permission, if not null
dd($user->can('create-tasks')); // will return true, if user has permission

 

Inside of our view files, we can use it like:

@role('developer')

 Hello developer

@endrole

 

This means only those user can see it whose role are developer. Now you can use many role as you want.

 

Step 10 : Setup the Middleware

 

Read also : How to Create Middleware with Parameters in Laravel 6

 

In order to protect our routes, we can setup the middleware to do so.

php artisan make:middleware RoleMiddleware

 

Add the middleware into your kernel & setup the handle method as follows

App\Http\Middleware\RoleMiddleware.php

namespace App\Http\Middleware;

use Closure;

class RoleMiddleware
{

    public function handle($request, Closure $next, $role, $permission = null)
    {
        if(!$request->user()->hasRole($role)) {

             abort(404);

        }

        if($permission !== null && !$request->user()->can($permission)) {

              abort(404);
        }

        return $next($request);

    }
}

 

Now we have to register this RoleMiddleware. So add this following code to register it.

App\Http\Kernel.php

protected $routeMiddleware = [
    .
    .
    'role' => \App\Http\Middleware\RoleMiddleware::class,
];

 

Right now in our routes, we can do something like this

Route::group(['middleware' => 'role:developer'], function() {

   Route::get('/admin', function() {

      return 'Welcome Admin';
      
   });

});

 

Now you can use your controller like below to give user permission and access.

public function __construct()
{
   $this->middleware('auth'); 
}


public function store(Request $request)
{
    if ($request->user()->can('create-tasks')) {
        //Code goes here
    }
}

public function destroy(Request $request, $id)
{   
    if ($request->user()->can('delete-tasks')) {
      //Code goes here
    }

}

 

Read also : Understanding Constructor and Method Dependency Injection in Laravel

 

Now only those user can access this route whose role is developer. Hope you will understand total procedure. Hope it will help you.

 

Laravel News Links

The Best Bug Repellents

https://cdn.thewirecutter.com/wp-content/uploads/2019/03/bug-repellent-lowres-9664-630×420.jpg

The Best Bug Repellents

Everyone should avoid bug bites. For a bug repellent that’s safe and effective—and that won’t stink or leave a puddle of oil on your skin—skip the DEET and get a picaridin formula, like Sawyer Products Premium Insect Repellent with 20 percent picaridin. It’s the best bottle of bug spray we found after testing 17 repellents and talking to everyone—from the EPA to the American Mosquito Control Association. One fact to establish up front: There’s no evidence that mosquitoes can transmit the coronavirus—but the diseases that biting insects do carry ain’t no picnic either.

Wirecutter: Reviews for the Real World

Snake Eyes’ First Trailer Gives a G.I. Joe Legend a New Beginning

https://i.kinja-img.com/gawker-media/image/upload/c_fill,f_auto,fl_progressive,g_center,h_675,pg_1,q_80,w_1200/ec1af9416e1223be47bac498723dc5b8.jpg

Henry Golding as Snake Eyes in Snake Eyes: G.I. Joe Origins.
Photo: Paramount

Trailer FrenzyA special place to find the newest trailers for movies and TV shows you’re craving.

When you think of Snake Eyes you think of the mask, the swords, the unstoppable ferocity. But how did the popular G.I. Joe character become that guy we’ve seen in comics, cartoons, and toy aisles for decades? We’re about to find out, in a whole new way. The first trailer for Snake Eyes: G.I. Joe Origins is finally here.

The film stars Henry Golding as the titular character, seen here years before he meets up with the Joe crew. Directed by Robert Schwentke, Snake Eyes follows the character as he becomes indoctrinated into the Arashikage clan, learning the ways of the ninja alongside Storm Shadow (Andrew Koji), the group’s heir apparent, and eventually popular Joe characters like The Baroness (Úrsula Corberó), and Scarlett (Samara Weaving) show up too. But this is the Snake Eyes show and, in the first trailer, you get just a taste of what the film has in store.

The film is meant to kick off a whole new G.I. Joe franchise and if you’re curious to know more, check back soon—io9 spoke to Henry Golding all about it. Snake Eyes: G.I. Joe Origins hits theaters on July 23.


For more, make sure you’re following us on our Instagram @io9dotcom.

G/O Media may get a commission

Gizmodo

They really are the enemy of the poeple

https://gunfreezone.net/wp-content/uploads/2016/01/cropped-gfz-ico.png

Tell me why the AP was in a building that Hamas was using to store weapons.

Oh yeah, because the AP were acting as human shields for Hamas, assuming that Israel wouldn’t strike their offices while Hamas hid rockets in the basement.

Everything the Left criticizes people for is projection.

They accuse Israel of war crimes because they were using media offices to protect terrorist weapons caches.

Friday Funnies

https://gunfreezone.net/wp-content/uploads/2021/05/lock-downs-no-emotional-harm-the-shinning.jpg

 

 

 

 

 

 

Hitman’s Wife’s Bodyguard (Trailer)

https://theawesomer.com/photos/2021/05/hitmans_wifes_bodyguard_t.jpg

Hitman’s Wife’s Bodyguard (Trailer)

Link

Ryan Reynolds, Samuel L. Jackson, Salma Hayek, Antonio Banderas, and Morgan Freeman star in this action-comedy about a bodyguard who attempts to get out of the business and gets pulled back in to protect the wife of an unhinged killer. It looks like just the kind of madcap Summer romp we could use. In theaters 6.16.2021.

The Awesomer

Holosun – How to Zero Your New Optic

https://www.ammoland.com/wp-content/uploads/2021/05/Holosun-Red-dot-500×334.jpg

Make Range Time Rounds Count with Holosun
Make Range Time Rounds Count with Holosun

U.S.A.-(AmmoLand.com)- One of the best things about some of the optics advancements in recent years has been the ability to incorporate them into all sorts of firearms, including pistols. This proves extremely beneficial for acquiring a target with as little effort as possible and takes the guesswork out of aiming. For a new and inexperienced marksman, this gives immediate results with little effort; that is, if it’s dialed in correctly.

Holosun offers a broad range of reflex sights that will work on properly equipped pistols. The 407, 507, 508 and 509 series come with all sorts of options. Mounting interface, reticle choice and color are the most obvious choices that need to be made. While these optics series are going to be different sizes, they are adjusted in remarkably similar ways.

When first using a reflex optic – let’s use the 508 series, for example – check to see if there are any specific items or tools necessary for adjustments. While the 508 series need a small flathead screwdriver, other brands may require custom tools and measurement systems. This is one significant benefit and testament to the consistency of Holosun products.

The Process:

Here’s a few basics before we begin on the overall process. Every optic will have a north-south knob for adjustment and an east-west knob for adjustment. Depending on where you aim and the location of the impacts, any changes to point-of-impact would be made using these knobs. Holosun includes a small tool that can be used for making these adjustments. Every time the knob is twisted, there will be a small ‘click’ sound. Each click is equivalent to a 1 MOA adjustment which may be unnecessary to know depending on your method for finding zero.

#1: With standard sight co-witness:

With some pistol optic installation, the ability to use the standard sights may still be possible. One method of zeroing a reflex optic is to line the dot from the optic over – or directly on – where the point of aim would normally be on the standard sights. There is some personal preference when it comes to co-witnessing. The next step would be as easy as heading to the range. From there, if the projectile is traveling too far in any direction, move the reticle an appropriate amount using the built-in knobs.

#2: Without co-witness:

A bit more complicated, this method can also be used even when co-witnessing. While you can eyeball it and waste ammunition in the process, a 10-yard zero target makes the process move without a hitch.

Pistol zero targets will most likely have an MOA measurement built-in. They are reliable if a target is set up at the proper distance. With an optic mounted and the target set up at ten yards, fire a group of 5 shots. From the shot group, find the center and estimate the MOA adjustments necessary to reach the bullseye. Using the dials on the side of the optic, adjust accordingly. Remember, Holosun pistol optic adjustment values are 1 MOA per click, so a 3 MOA adjustment would be three clicks.

Final Steps:

Following any adjustments, it’s recommended to do the same target process 3-5 times. After each group, continue making slight adjustments if necessary. This will do several things.

  • First, it will work out the user’s cobwebs and any flinching that might have happened during the first group shots.
  • Second, it will allow the settling in of any irregularities with the pistol, such as lack of lubrication or magazine difficulties.
  • Third, it will also test the consistency of the ammunition itself. Ammunition is one of the largest uncontrollable variables when finding zero and the accuracy of any firearm.

Conclusion:

So, there you have it! Two methods of zeroing your pistol-mounted optic. Promptly, find some inexpensive ammunition and get out to the range. The only thing standing in the way of an accurate pistol is you… and ammunition prices…


About Holosun Technologies

Holosun Technologies, located in City of Industry, California, was established in 2013 by one of the industry’s most successful OEM manufacturers. Holosun is committed to creating innovative optic, laser/IR technologies that benefit a broad range of shooting, hunting, law enforcement, and military needs.

Over the course of the past decade, Holosun has been at the forefront of developing new sight technologies to fulfill a variety of shooting needs. Our product line includes innovations such as; 50,000 hr battery life, solar options, the ability to change reticles with the press of a button and IR/Laser units that utilize the most recent advancements in laser and LED technology. At Holosun, we pride ourselves on producing cutting-edge equipment with a competitive price that astounds the customer and the competition.

For more information, please visit WWW.HOLOSUN.COM

Holosun logo

The post Holosun – How to Zero Your New Optic appeared first on AmmoLand.com.

AmmoLand.com