承接 stechstudio/laravel-route-context 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

stechstudio/laravel-route-context

Composer 安装命令:

composer require stechstudio/laravel-route-context

包简介

Provide additional route context that gets treated as normal route parameters

README 文档

README

Latest Version on Packagist

This is a super small package that enables you to provide additional context to your routes. Any context variables you specify will be treated as route parameters.

Installation

You know the drill...

composer require stechstudio/laravel-route-context

Usage

The idea is that sometimes you want to reuse a controller method or Livewire fullpage component, while providing additional context at the routing layer.

Imagine you need to list support tickets, and you have a controller and view that handles this. You have multiple endpoints where tickets might be displayed in a slightly different manner.

With this package you can specify additional context right alongside your routes like this:

Route::get('tickets', [TicketController::class, 'index']);
Route::get('tickets/archived', [TicketController::class, 'index'])->with([
    'archived' => true
]);
Route::get('tickets/mine', [TicketController::class, 'index'])->with([
    'user' => fn() => auth()->user()
]);
Route::get('tickets/{user}', [TicketController::class, 'index']);

Now in your TicketController you can inject your context variables, just as if they had been route parameters:

public function index(User $user, $archived = false) {
    $tickets = Tickets::query()
        ->when($user->exists, fn($q) => $q->where('user_id', $user->id))
        ->when(!$archived, fn($q) => $q->whereNull('archived_at'))
        ->paginate();
}

Notice that context values can be callbacks, if you need it evaluated after your app has bootstrapped, session is started, auth is available, etc.

License

The MIT License (MIT). Please see License File for more information.

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 2
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2022-01-06

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固