<?php
use Illuminate\Support\Facades\Route;
use Illuminate\Support\Facades\Auth;
use App\Http\Controllers\AdminViewOrders;
// Use Local
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
// ------------------------------------------------- Route admin ------------------------------------------------------------------
/*Route::get('/admin-panel', function () {
if (Auth::user()->status == 'admin') {
return view('admin-page');
}
})->middleware(['auth'])->name('admin-page'); */
Route::get('/admin-panel', 'App\Http\Controllers\AdminViewOrders@StatsView')->middleware(['auth'])->name('admin-page');
Route::get('/admin-panel/users', 'App\Http\Controllers\AdminViewOrders@ViewUsers')->middleware(['auth'])->name('admin-users');
Route::get('admin-panel/orders/{method}/{id}', 'App\Http\Controllers\AdminViewOrders@OrderStatus')->middleware(['auth']);
Route::get('admin-panel/create-services', 'App\Http\Controllers\ServicesContrtoller@CreateServicesPage')->middleware(['auth'])->name('create-services');
Route::post('admin-panel/create-services/create', 'App\Http\Controllers\ServicesContrtoller@CreateServices')->middleware(['auth']);
Route::get('admin-panel/services/{id}', 'App\Http\Controllers\ServicesContrtoller@ServicesRedactor')->middleware(['auth'])->name('services-redactor');
Route::get('/admin-panel/orders', 'App\Http\Controllers\AdminViewOrders@ViewOrders')->middleware(['auth'])->name('orders');
Route::get('/admin-panel/orders/{id}', 'App\Http\Controllers\AdminViewOrders@ViewOrdersPage')->middleware(['auth'])->name('order-page');
<?php
namespace App\Providers;
use Illuminate\Cache\RateLimiting\Limit;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
use Illuminate\Support\Facades\Route;
class RouteServiceProvider extends ServiceProvider
{
/**
* The path to the "home" route for your application.
*
* This is used by Laravel authentication to redirect users after login.
*
* @var string
*/
public const HOME = '/dashboard';
/**
* The controller namespace for the application.
*
* When present, controller route declarations will automatically be prefixed with this namespace.
*
* @var string|null
*/
// protected $namespace = 'App\\Http\\Controllers';
/**
* Define your route model bindings, pattern filters, etc.
*
* @return void
*/
public function boot()
{
$this->configureRateLimiting();
$this->routes(function () {
Route::prefix('api')
->middleware('api')
->namespace($this->namespace)
->group(base_path('routes/api.php'));
Route::middleware('web')
->namespace($this->namespace)
->group(base_path('routes/web.php'));
Route::middleware(['web', 'can:view-admin'])
->namespace($this->namespace)
->group(base_path('routes/admin/web.php'));
});
}
/**
* Configure the rate limiters for the application.
*
* @return void
*/
protected function configureRateLimiting()
{
RateLimiter::for('api', function (Request $request) {
return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip());
});
}
}
<?php
namespace App\Providers;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Gate;
use Illuminate\Support\Facades\Auth;
use App\Models\User;
class AuthServiceProvider extends ServiceProvider
{
/**
* The policy mappings for the application.
*
* @var array
*/
protected $policies = [
// 'App\Models\Model' => 'App\Policies\ModelPolicy',
];
/**
* Register any authentication / authorization services.
*
* @return void
*/
public function boot()
{
$this->registerPolicies();
// my code
Gate::define('view-admin', function (User $user) {
if(Auth::user()->status == 'admin') {
return $user->is_admin;
}
});
}
}
Argument 1 passed to App\Providers\AuthServiceProvider::App\Providers\{closure}() must be an instance of App\Providers\User, instance of App\Models\User given, called in D:\Server\OpenServer\domains\lesons-app\vendor\laravel\framework\src\Illuminate\Auth\Access\Gate.php on line 474
Gate::define('view-admin', function (User $user) {
if(Auth::user()->status == 'admin') {
return $user->is_admin;
}
});
public function ViewServices () {
$services = new MainModel();
return view('mservices', ['services' =>$services->all()]);
}