问题
I have created four user type admin,vendor,employee,customer
. In the user migration file I have the following:
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('email')->unique();
$table->char('contact',24)->nullable();
$table->string('password');
$table->enum('roles',['admin', 'vendor', 'employee', 'customers']);
$table->string('image')->nullable();
$table->timestamps();
});
}
I have already created middleware for all user type. Admin middleware
public function handle($request, Closure $next)
{
if ($request->user()->roles == 'admin'){
return $next($request);
} else {
return redirect()->route($request->user()->roles);
}
}
Customer middleware
public function handle($request, Closure $next)
{
if ($request->user()->roles == 'customer'){
return $next($request);
} else {
return redirect()->route($request->user()->roles);
}
}
Vendor middleware
public function handle($request, Closure $next)
{
if ($request->user()->roles == 'vendor'){
return $next($request);
} else {
return redirect()->route($request->user()->roles);
}
}
Employee middleware
public function handle($request, Closure $next)
{
if ($request->user()->roles == 'employee'){
return $next($request);
} else {
return redirect()->route($request->user()->roles);
}
}
I have included all the middleware in the Kernel.php
.
Now I want to assign one route to multiple users. For example, Admin and vendor can add
, edit
, update
, delete
product while Employee can only edit
, s/he can neither add
nor delete
. I want to sensitive route to admin only.
Answer with explanation will be highly appreciated!
来源:https://stackoverflow.com/questions/63130329/assigning-one-route-to-multiple-user-without-a-package-in-laravel