PHP code example of stechstudio / laravel-route-context

1. Go to this page and download the library: Download stechstudio/laravel-route-context 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/ */

    

stechstudio / laravel-route-context example snippets


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']);

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();
}