PHP code example of jjg / admin
1. Go to this page and download the library: Download jjg/admin library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
jjg / admin example snippets
use Illuminate\Auth\AuthenticationException;
/**
* Render an exception into an HTTP response.
* @param \Illuminate\Http\Request $request
* @param Exception $exception
* @return \Illuminate\Http\RedirectResponse|\Symfony\Component\HttpFoundation\Response
*/
public function render($request, Exception $exception)
{
if ($exception instanceof AuthorizationException) {
return redirect()->guest(route('admin.permission-denied'));
}
return parent::render($request, $exception);
}
/**
* Convert an authentication exception into a response.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Auth\AuthenticationException $exception
* @return \Illuminate\Http\Response
*/
protected function unauthenticated($request, AuthenticationException $exception)
{
// 自定义登录跳转-通过路由前缀判断
$action = $request->route()->getAction();
$redirectUrl = (isset($action['prefix']) && (config('admin.route.prefix') == $action['prefix'] || '/' . config('admin.route.prefix') == $action['prefix'])) ?
route('admin.login') : route('login');
return $request->expectsJson()
? response()->json(['message' => $exception->getMessage()], 401)
: redirect()->guest($redirectUrl);
// return $request->expectsJson()
// ? response()->json(['message' => $exception->getMessage()], 401)
// : redirect()->guest(route('login'));
}
//## 路由:{model}
//$router->get('files', 'FilesController@index')->name('admin.files');
//$router->get('files/create', 'FilesController@create')->name('admin.files.create');
//$router->get('files/list', 'FilesController@list')->name('admin.files.list');
//$router->post('files/store', 'FilesController@store')->name('admin.files.store');
//$router->get('files/edit/{file}', 'FilesController@edit')->name('admin.files.edit');//隐式绑定
//$router->post('files/update/{file}', 'FilesController@update')->name('admin.files.update');//隐式绑定
//$router->get('files/destroy/{file}', 'FilesController@destroy')->name('admin.files.destroy');//隐式绑定
//$router->post('files/destroyBat', 'FilesController@destroyBat')->name('admin.files.destroyBat');
'menu_left' =>[
[
"id" => "files",
"text" => "文件管理",
"permission" => function () {
return true;
},
"icon" => "layui-icon layui-icon-file",
"route" => "admin.files",//优先级第二
"params" => [],
"query" => [],//优先级第三
"link" => "",//优先级第一
],
]
php artisan vendor:publish --provider="Ml\Providers\MlServiceProvider"
php artisan mlAdmin:install
namespace App\Providers;
use Illuminate\Foundation\Support\Providers\AuthServiceProvider as ServiceProvider;
class AuthServiceProvider extends ServiceProvider
{
/**
* The policy mappings for the application.
*
* @var array
*/
protected $policies = [
'App\Models\BaseModel' => 'App\Policies\Policy',
'App\Models\User' => 'App\Policies\UserPolicy',//注册策略类
\Spatie\Permission\Models\Role::class => \App\Policies\RolePolicy::class,
\Spatie\Permission\Models\Permission::class => \App\Policies\PermissionPolicy::class,
];
/**
* Register any authentication / authorization services.
*
* @return void
*/
public function boot()
{
$this->registerPolicies();
//
}
}
php artisan mlAdmin:create-user
php artisan serve