Laravel ??????? ???? ?? ?? ?? ??? ??? ? ???, ?? ?? ?? ??? ??? ?? ?? ??? ?? ?? ?? ?????. ? ??? ?????? ?? ?? ???? ???? ??? ????? ????? ?? ??, ?? ? ??? ? ?? ??? ??? ?????.
??
?? Laravel ?????? ???? ???? ???? ???? ?? ???? ?????.
@can('viewAdmin') <a href="{{ route('administration.index') }}"> {{ __('Administration') }} </a> @endcan
? ?? ??? ??? ???????? ?????? ?? ?? ???? ????? ???? ??????.
???
?? ?? ???? ?? ??? ??? ??? ???? ????? ??? ?????.
- ?????: ?? ??? ?? ??.
- ???: ???? ??? ?? ??? ???? ?????.
- ????: ?? ??? ??? ?????.
?? ??? ???? ??? ????? ?? ?????? ? ??? ??? ???. ???? ??? ??? ??, ???, ???? ???? ???? ? ??? ???. ???? ??? ?????.
??? ??
1. viewAdmin? ?? ??? ??
?? ??? ?? ???? ????? AuthServiceProvider?? viewAdmin ???? ?????.
use Illuminate\Support\Facades\Gate; use App\Models\User; class AuthServiceProvider extends ServiceProvider { public function boot() { $this->registerPolicies(); Gate::define('viewAdmin', function (User $user) { return $user->hasRole('admin'); // Replace with your app's role-checking logic }); } }
2. MenuItem ??? ??
MenuItem ???? ??, URL, ???, ??? ? ?? ??? ?? ??? ?????.
<?php namespace App\Actions\Builder; use CleaniqueCoders\Traitify\Contracts\Builder; use InvalidArgumentException; class MenuItem implements Builder { private string $label; private string $url; private string $target = '_self'; private array $attributes = []; private array $children = []; private string $icon = 'o-squares-2x2'; private ?string $description = null; private ?string $tooltip = null; private $visible = true; private array $output = []; public function setLabel(string $label): self { $this->label = $label; return $this; } public function setUrl(string $url): self { $this->url = $url; return $this; } public function setTarget(string $target): self { $this->target = $target; return $this; } public function addAttribute(string $key, string $value): self { $this->attributes[$key] = $value; return $this; } public function addChild(MenuItem $child): self { $this->children[] = $child; return $this; } public function setIcon(string $icon): self { $this->icon = $icon; return $this; } public function setDescription(string $description): self { $this->description = $description; return $this; } public function setTooltip(string $tooltip): self { $this->tooltip = $tooltip; return $this; } public function setVisible($visible): self { if (! is_bool($visible) && ! is_callable($visible)) { throw new InvalidArgumentException('The visible property must be a boolean or a callable.'); } $this->visible = $visible; return $this; } public function isVisible(): bool { return is_callable($this->visible) ? call_user_func($this->visible) : $this->visible; } public function build(): self { $this->output = [ 'label' => $this->label, 'url' => $this->url, 'target' => $this->target, 'attributes' => $this->attributes, 'icon' => $this->icon, 'description' => $this->description, 'tooltip' => $this->tooltip, 'children' => array_filter( array_map(fn (MenuItem $child) => $child->build()->toArray(), $this->children), fn (array $child) => ! empty($child) ), ]; return $this; } public function toArray(): array { return $this->output; } public function toJson(int $options = 0): string { return json_encode($this->toArray(), $options, 512); } }
3. ?? ?? ???
?? ??? ??? ???? ???? ?????.
namespace App\Actions\Builder; class Menu { public static function make() { return new self; } public function build(string $builder) { $class = match ($builder) { 'navbar' => Navbar::class, 'sidebar' => Sidebar::class, 'administration' => Administration::class, default => Navbar::class, }; $builder = new $class; return $builder->build(); } }
??? ??? ???? ??? ???:
<?php use App\Actions\Builder\Menu; if (! function_exists('menu')) { function menu(string $builder) { return Menu::make()->build($builder)->menus(); } }
4. ????
?? ????? ?? ?? ?? ?? ??:
<?php namespace App\Actions\Builder\Menu; use App\Actions\Builder\MenuItem; use CleaniqueCoders\Traitify\Contracts\Builder; use CleaniqueCoders\Traitify\Contracts\Menu; use Illuminate\Support\Collection; use Illuminate\Support\Facades\Gate; class Administration implements Builder, Menu { private Collection $menus; public function menus(): Collection { return $this->menus; } public function build(): self { $this->menus = collect([ (new MenuItem) ->setLabel(__('Issues')) ->setUrl(url(config('telescope.path'))) ->setTarget('_blank') ->setVisible(fn () => Gate::allows('viewTelescope')) ->setTooltip(__('View Telescope issues')) ->setDescription(__('Access application issues using Laravel Telescope')) ->setIcon('o-bug'), // Heroicon outline for a bug (new MenuItem) ->setLabel(__('Queues')) ->setUrl(url(config('horizon.path'))) ->setTarget('_blank') ->setVisible(fn () => Gate::allows('viewHorizon')) ->setTooltip(__('Manage queues')) ->setDescription(__('Access Laravel Horizon to monitor and manage queues')) ->setIcon('o-cog'), // Heroicon outline for settings/tasks (new MenuItem) ->setLabel(__('Access Control')) ->setUrl(route('security.access-control.index')) ->setVisible(fn () => Gate::allows('viewAccessControl')) ->setTooltip(__('Manage access control')) ->setDescription(__('Define and manage access control rules')) ->setIcon('o-lock-closed'), (new MenuItem) ->setLabel(__('Users')) ->setUrl(route('security.users.index')) ->setVisible(fn () => Gate::allows('viewUser')) ->setTooltip(__('Manage users')) ->setDescription(__('View and manage user accounts')) ->setIcon('o-user-group'), (new MenuItem) ->setLabel(__('Audit Trail')) ->setUrl(route('security.audit-trail.index')) ->setVisible(fn () => Gate::allows('viewAudit')) ->setTooltip(__('View audit trails')) ->setDescription(__('Audit logs for security and activity tracking')) ->setIcon('o-document-text'), ])->reject(fn (MenuItem $menu) => ! $menu->isVisible()) ->map(fn (MenuItem $menu) => $menu->build()->toArray()); return $this; } }
5. ?? ??
?? ???? ?? ?? ??? ?????.
<?php use Illuminate\Support\Facades\Route; Route::middleware(['auth:sanctum', 'verified', 'can:viewAdmin']) ->as('administration.') ->prefix('administration') ->group(function () { Route::view('/', 'administration.index')->name('index'); });
6. ???? ?????? ???
?? ??(navigation-menu.blade.php):
@can('viewAdmin') <a href="{{ route('administration.index') }}"> <x-icon name="o-computer-desktop" /> {{ __('Administration') }} </a> @endcan
?? ??(administration/index.blade.php):
<x-app-layout> <x-slot name="header">{{ __('Administration') }}</x-slot> <div> <hr> <p><strong>??</strong></p> <p>??? ?? ? ?? ?? ??? ??? ????.</p> <p><img src="/static/imghw/default1.png" data-src="https://img.php.cn/upload/article/000/000/000/173418649412401.jpg" class="lazy" alt="Building Dynamic and Maintainable Menus in Laravel"></p><blockquote> <p>?? ??? ???? ??? ????? ?? ?????? ? ??? ??? ???. ???? ??? ??? ??, ???, ???? ???? ???? ? ??? ???. ???? ??? ?????.</p> </blockquote> <hr> <h3> <strong>??</strong> </h3> <p>? <strong>?? ?? ???</strong>? ??? ?? Laravel? ?? ??? ??????.</p> <ol> <li>? ?? ?? ??? ?? ?? ??? ?? ??????.</li> <li>???? ??? ???? ?? ???? ???? ?????.</li> <li>?? ???? ??? ?? ?? ??? ??????.</li> </ol> <p>? ?? ??? ???? ??? ????????? ????? ???? ???? ??? ? ????. </p> <p>???????? ?? ????? ???? ??? ??? ??? ? ????. ??? ???? ? ??? ????. ?????? ?? ?? ??? ???? ?? ????? ????.</p> <p>??? ???? ??? ? ????. </p> <p>????? ??? ??? ???! ?</p> <hr> <p>??: LinedPhoto, Unsplash</p>
? ??? Laravel?? ???? ?? ?? ??? ?? ???? ?? ?????. ??? ??? PHP ??? ????? ?? ?? ??? ?????!

? AI ??

Undress AI Tool
??? ???? ??

Undresser.AI Undress
???? ?? ??? ??? ?? AI ?? ?

AI Clothes Remover
???? ?? ???? ??? AI ?????.

Clothoff.io
AI ? ???

Video Face Swap
??? ??? AI ?? ?? ??? ???? ?? ???? ??? ?? ????!

?? ??

??? ??

???++7.3.1
???? ?? ?? ?? ???

SublimeText3 ??? ??
??? ??, ???? ?? ????.

???? 13.0.1 ???
??? PHP ?? ?? ??

???? CS6
??? ? ?? ??

SublimeText3 Mac ??
? ??? ?? ?? ?????(SublimeText3)

? ?? PHP ??? ???? ?? ? ?? ????? ? ?? ?? ??? ????. 1. ??? ??? ?? ?? ??? ?? Array_Merge ? Array_unique ??? ??????. ?? Array_Merge ($ array1, $ array2)? ?? ? ?? Array_Unique ()? ???? ?? ?? ? ?? ???? ? ??? ?????. 2. ?? ?? ? ? ?? ???? ? ? ?? ????? ???? ??????. $ result = $ array1 $ array2? ? ?? ??? ?? ? ?? ??? ?? ?? ?? ??????. ? ? ?? ??? ? ??? ????? ??? ?? ?

????? ??? ????? ????? ??? ??? ???????. ?? ?? ??? ??? ????. 1. ??? 8 ?? ?????. 2. ??? ???, ??? ? ??? ?????. 3. ?? ?? ??? ?? ? ? ????. ?? ??? ????, ??? ???? ?? ? ??/?? ???? ?????, ?? PHP ?? ??? ?????. ???, ?????? ???? ?? ? 123456? ?? ???? ?? ??? ????????. ????? ?? ???? ????? ?? ZXCVBN ?????? ???? ?? ????.

PHP ?? ???? ???? ????? ?? ? ??? ???? ?? ?? ? ??? ???? ?? ??? ?????? ??? ??? ? ? ???????. 1. ??? ?? CSRF? ???? ?? ??? ??? ???? ?????? ??? ???? FINFO_FILE? ?? ?? MIME ??? ?????. 2. ??? ??? ??? ???? ??? ?? ??? ?? ? WEB ????? ??? ???? ??????. 3. PHP ?? ??? ?? ? ?? ???? NGINX/APACHE? ??? ????? ?? ???? ?????. 4. GD ?????? ??? ? ?? ???? ??? ?? ??? ?? ????.

PHP ?? ??? ?? ???? ?? ? ????? ??? ?????. 1. ?? ??? ??? ??? ??? ? ? ??? ??? ??? ?? ?? ??? ???? ???????. 2. ?? ??? ???? ???? ? ?? ????? ?? ?? ?? ??? ?????. 3. $ _get ? $ _post? ?? Hyperglobal ??? ?? ???? ?? ??? ? ??? ??? ??????? ???????. 4. ?? ?? ?? ???? ?? ?? ?? ??? ?????? ?? ??? ??? ?? ??? ???????. ??? ??? ????? ??? ??? ?? ???? ????? ? ??? ? ? ????.

PHP ?? ???? ? ?? ???? ??? ????. 1. // ?? #? ???? ? ?? ??? ???? // ???? ?? ????. 2. ?? /.../ ?? ?? ?? ??? ????? ?? ? ?? ??? ?? ? ? ????. 3. ?? ?? ?? / if () {} /? ?? ?? ??? ????? ??? ?? ?? ?? ??? ???? ????? ???? ??? ?? ???? ???? ??? ? ??? ??????.

PHP ??? ???? ??? ??? ??? ????? ????. ??? ????? ?? ???? ??? "?? ? ?"??? "?"? ???????. 1. ??? ? ??? ??? DocBlock (/*/)? ?? ?? ??? ???? ??? ? ?? ???? ??????. 2. JS ??? ???? ?? ???? ??? ?? ??? ??? ?????. 3. ??? ?? ?? ?? ??? ???? ????? ????? ???? ?? ????? ???? ? ??????. 4. Todo ? Fixme? ????? ???? ? ? ??? ??? ???? ?? ?? ? ??? ???????. ??? ???? ?? ??? ??? ?? ?? ?? ???? ???? ? ????.

Ageneratorinphpisamemory- ???? Way-Erate-Overgedatasetsetsbaluesoneatimeatimeatimeatimallatonce.1.generatorsuseTheyieldKeywordTocroadtOpvaluesondemand, RetingMemoryUsage.2

PHP?? ??? ???? ? ?? ??? ???? : ?? () ??? ????? ???? ?????? []. 1. ?? () ??? ???? ?? ???? ???? ???? ?????. $ fruits = array ( "Apple", "Banana", "Orange")? ?? ??? ???? ???? $ user = array ( "name"=> "john", "age"=> 25)? ?? ?? ??; 2. [] ??? $ color? ?? PHP5.4 ??? ? ??? ?? ?????.
