### Install Laravel Views Package Source: https://context7.com/gustavinho/laravel-views/llms.txt Install the package via Composer and publish its assets and configuration files. ```bash composer require laravel-views/laravel-views # Publish public assets (JS, CSS) php artisan vendor:publish --tag=public --provider='LaravelViews\LaravelViewsServiceProvider' # Optionally publish the config file php artisan vendor:publish --tag=config --provider='LaravelViews\LaravelViewsServiceProvider' # Optionally publish Blade views for customization php artisan vendor:publish --tag=views --provider='LaravelViews\LaravelViewsServiceProvider' ``` -------------------------------- ### Artisan Scaffold Commands for Views Source: https://context7.com/gustavinho/laravel-views/llms.txt Generate boilerplate class files for different types of views, filters, and actions using Artisan commands. ```bash # Create a new TableView class php artisan make:table-view UsersTableView # Create a new GridView class php artisan make:grid-view ProductsGridView # Create a new ListView class php artisan make:list-view OrdersListView # Create a filter class php artisan make:filter ActiveUsersFilter # Create an action class php artisan make:action DeleteUserAction # Generic make command (prompts for type) php artisan make:view MyView ``` -------------------------------- ### Implement Products GridView Source: https://context7.com/gustavinho/laravel-views/llms.txt Extend GridView to display products as responsive cards. Implement the card() method to define data passed to each card. Configure search fields, maximum columns, background styling, and sortable options. ```php 'Name', 'price' => 'Price', 'created_at' => 'Newest', ]; } /** Data passed to each card component */ public function card($model): array { return [ 'title' => $model->name, 'image' => $model->image_url, 'subtitle' => '$' . number_format($model->price, 2), ]; } /** Navigate to a detail page when a card is clicked */ public function onCardClick($model) { return redirect()->route('products.show', $model); } protected function filters(): array { return [new CategoryFilter]; } } ``` -------------------------------- ### Use RedirectAction for Navigation Source: https://context7.com/gustavinho/laravel-views/llms.txt Employ RedirectAction for straightforward navigation without defining a custom action class. Specify the route, link text, and an optional icon. ```php use LaravelViews\Actions\RedirectAction; protected function actionsByRow(): array { return [ new RedirectAction('users.edit', 'Edit', 'edit'), new RedirectAction('users.show', 'View', 'eye'), ]; } ``` -------------------------------- ### Implement Users TableView Source: https://context7.com/gustavinho/laravel-views/llms.txt Extend TableView to create a searchable, filterable, and sortable data table for users. Implement headers() and row() methods for column definitions and data retrieval. Configure search fields, pagination, filters, and row actions. ```php with('roles')->where('verified', true); // } // Fields to search across (supports dot-notation for relations) public $searchBy = ['name', 'email', 'roles.name']; // Items per page protected $paginate = 15; /** Column headers */ public function headers(): array { return [ Header::title('Name')->sortBy('name'), Header::title('Email')->sortBy('email')->width('250px'), Header::title('Status'), Header::title('Created'), ]; } /** Row data — called once per item */ public function row($model): array { return [ $model->name, $model->email, UI::badge($model->active ? 'Active' : 'Inactive', $model->active ? 'success' : 'danger'), $model->created_at->format('Y-m-d'), ]; } /** Filters shown in the toolbar */ protected function filters(): array { return [ new ActiveUsersFilter, ]; } /** Per-row action buttons */ protected function actionsByRow(): array { return [ new EditUserAction, new DeleteUserAction, ]; } /** Bulk actions (appear when rows are selected) */ protected function bulkActions(): array { return [ new DeleteUserAction, ]; } } ``` -------------------------------- ### Configure Sortable Column Headers with Header Facade Source: https://context7.com/gustavinho/laravel-views/llms.txt Use the Header facade to define column configurations for TableView, including simple titles, sortable columns by database fields, and fixed column widths. ```php use LaravelViews\Facades\Header; public function headers(): array { return [ // Simple non-sortable header Header::title('Avatar'), // Sortable by a database column Header::title('Name')->sortBy('name'), // Sortable with a fixed column width Header::title('Email')->sortBy('email')->width('200px'), // Fixed width only (not sortable) Header::title('Actions')->width('120px'), ]; } ``` -------------------------------- ### Create a DetailView Component Source: https://context7.com/gustavinho/laravel-views/llms.txt Extend LaravelViews\Views\DetailView to display details of a single Eloquent model. Implement the detail() method to define the attributes to show. Supports custom headings and actions. ```php name, $model->email]; } /** Return an associative array for a default attributes list */ public function detail($model): array { return [ 'Name' => $model->name, 'Email' => $model->email, 'Role' => $model->role, 'Registered' => $model->created_at->format('F j, Y'), 'Status' => $model->active ? 'Active' : 'Inactive', ]; } public function actions(): array { return [ new EditUserAction, new DeleteUserAction, ]; } } ``` -------------------------------- ### Render UI Components with UI Facade Source: https://context7.com/gustavinho/laravel-views/llms.txt Utilize the UI facade for inline rendering of badges, avatars, links, icons, editable fields, attribute lists, and custom Blade components within Laravel Views. ```php use LaravelViews\Facades\UI; // Badge: UI::badge(string $title, string $type = 'default') // Types: 'success', 'danger', 'warning', 'info', 'default' UI::badge('Active', 'success'); UI::badge('Banned', 'danger'); // Avatar image (circular) UI::avatar($user->avatar_url); // Clickable link UI::link('View profile', route('users.show', $user)); // Feather icon with optional type/class UI::icon('check-circle', 'success'); UI::icon('alert-triangle', 'warning', 'ml-2'); // Inline editable field (inline editing) UI::editable($model, 'name'); // Attributes list (for DetailView) UI::attributes(['Name' => $user->name, 'Email' => $user->email], ['stripe' => true]); // Custom Blade component UI::component('components.my-badge', ['label' => 'Custom']); ``` -------------------------------- ### Publish public assets Source: https://github.com/gustavinho/laravel-views/blob/master/README.md The main JavaScript and CSS files have changed in version 2.3. Re-publish the public assets to include the updated files. ```bash php artisan vendor:publish --tag=public --provider='LaravelViews\LaravelViewsServiceProvider' --force ``` -------------------------------- ### Create a ListView Component Source: https://context7.com/gustavinho/laravel-views/llms.txt Extend LaravelViews\Views\ListView to render items as a vertical list. Implement the item() method to define the data for each list item. Supports search, filters, and sortable columns. ```php 'Date', 'total' => 'Total']; } /** Data passed to each list item component */ public function item($model): array { return [ 'title' => 'Order #' . $model->reference, 'subtitle' => $model->customer_name, 'value' => UI::badge('$' . $model->total, 'info'), ]; } protected function actionsByRow(): array { return [new ViewOrderAction]; } } ``` -------------------------------- ### Implement a Date Filter Source: https://context7.com/gustavinho/laravel-views/llms.txt Create a date picker filter by extending LaravelViews\Filters\DateFilter. The apply() method receives a Carbon instance for date comparisons. ```php whereDate('created_at', '>=', $value); } } ``` -------------------------------- ### Publish Blade components Source: https://github.com/gustavinho/laravel-views/blob/master/README.md If you have previously published and customized internal Blade components, you need to publish them again after upgrading to ensure you have the latest versions. ```bash php artisan vendor:publish --tag=views --provider='LaravelViews\LaravelViewsServiceProvider' ``` -------------------------------- ### Render View with Layout Source: https://context7.com/gustavinho/laravel-views/llms.txt Embed a view within an existing Blade layout using a named section. This is useful when not using Livewire's full-page components. ```php use LaravelViews\Facades\LaravelViews; // In a controller method public function index() { $html = LaravelViews::create(new UsersTableView) ->layout('layouts.app', 'content', ['pageTitle' => 'Users']) ->render(); return response($html); } // Or pass the rendered HTML directly to a view return view('admin.dashboard', [ 'usersTable' => LaravelViews::create(new UsersTableView)->render(), ]); ``` -------------------------------- ### Implement Custom Action in Laravel Views Source: https://context7.com/gustavinho/laravel-views/llms.txt Extend LaravelViews\Actions\Action and implement the handle() method. Use $this->success() or $this->error() for feedback. The renderIf() method can conditionally display the action. ```php id() !== $item->id; } /** $item is the Eloquent model for row actions, or an array of IDs for bulk actions */ public function handle($item, View $view = null) { try { $item->update(['active' => !$item->active]); $this->success('User status updated successfully.'); } catch (\Exception $e) { $this->error('Could not update user status.'); } } } ``` -------------------------------- ### Implement Confirmable Action for User Deletion Source: https://context7.com/gustavinho/laravel-views/llms.txt Add the Confirmable trait to an action to prompt the user for confirmation before execution. Customize the confirmation message using getConfirmationMessage(). ```php name}?" : 'Are you sure you want to delete the selected users?'; } public function handle($item, $view = null) { is_array($item) ? \App\Models\User::destroy($item) : $item->delete(); $this->success('Deleted successfully.'); } } ``` -------------------------------- ### Include ListView in Blade Source: https://context7.com/gustavinho/laravel-views/llms.txt Render the ListView component in your Blade views using the livewire directive. ```blade ``` -------------------------------- ### Refactor repository method to use $model property Source: https://github.com/gustavinho/laravel-views/blob/master/README.md For views where the repository() method returns a simple query object, consider defining a protected $model property instead. This is the new default behavior and can simplify your code. ```php /* Before */ public function repository(): Builder { // You are using a single query return User::query(); } /** After */ protected $model = User::class; ``` -------------------------------- ### Customize Tailwind CSS Classes with Variants Facade Source: https://context7.com/gustavinho/laravel-views/llms.txt The Variants facade allows global UI customization by reading Tailwind CSS class strings from config/laravel-views.php, affecting buttons, badges, and alerts. ```php // config/laravel-views.php return [ 'buttons' => [ 'primary' => 'text-white bg-indigo-600 hover:bg-indigo-700 focus:ring-indigo-500', 'danger' => 'text-white bg-red-600 hover:bg-red-700 focus:ring-red-500', ], 'badges' => [ 'success' => 'bg-green-200 text-green-800', 'danger' => 'bg-red-200 text-red-800', ], 'alerts' => [ 'success' => [ 'base' => 'bg-green-100 border-green-300 text-green-700', 'icon' => 'bg-green-200', 'title' => 'text-green-900', ], ], ]; ``` ```php use LaravelViews\Facades\Variants; // In a Blade component or custom template: $buttonClass = Variants::button('primary')->class(); $badgeClass = Variants::badge('success')->class(); $alertBase = Variants::alert('success')->class('base'); $alertTitle = Variants::alert('success')->class('title'); $alertIcon = Variants::alert('success')->icon(); // 'check' $alertLabel = Variants::alert('success')->title(); // 'Success' ``` -------------------------------- ### Implement a Select Filter Source: https://context7.com/gustavinho/laravel-views/llms.txt Create a dropdown filter by extending LaravelViews\Filters\Filter. Implement title(), options(), and apply() methods. A default value can be set using $defaultValue. ```php 'Active', 'inactive' => 'Inactive', 'banned' => 'Banned', ]; } public function apply(Builder $query, $value): Builder { return $query->where('status', $value); } } ``` -------------------------------- ### Include Assets in Blade Layout Source: https://context7.com/gustavinho/laravel-views/llms.txt Inject the necessary CSS and JavaScript assets into your main Blade layout using provided directives. ```blade @laravelViewsStyles {{-- Load only specific assets --}} {{-- @laravelViewsStyles('livewire,tailwindcss') --}} {{ $slot }} @laravelViewsScripts {{-- Load only specific assets --}} {{-- @laravelViewsScripts('livewire,alpine,laravel-views') --}} ``` -------------------------------- ### Update renderIf() method signature Source: https://github.com/gustavinho/laravel-views/blob/master/README.md When upgrading to version 2.3, update the renderIf() function in your action classes by adding a new $view parameter. ```php ``` -------------------------------- ### Include DetailView in Blade Source: https://context7.com/gustavinho/laravel-views/llms.txt Render the DetailView component in your Blade views, passing either a model instance or its ID. ```blade {{-- Pass a model instance or ID --}} ``` -------------------------------- ### Implement a Boolean Filter Source: https://context7.com/gustavinho/laravel-views/llms.txt Create a checkbox filter by extending LaravelViews\Filters\BooleanFilter. Define the filter options and the apply() method to handle the query logic. ```php filter()->keys(); return $active->isNotEmpty() ? $query->whereIn('role', $active) : $query; } } ``` -------------------------------- ### Render TableView Component Source: https://context7.com/gustavinho/laravel-views/llms.txt Render the TableView component directly in a Blade view using its livewire tag, or programmatically within a controller using the LaravelViews facade. ```blade // In a Blade view ``` ```php // Or render via the LaravelViews facade inside a controller use LaravelViews\Facades\LaravelViews; return view('admin.users', [ 'view' => LaravelViews::create(new UsersTableView)->render(), ]); ``` -------------------------------- ### Clear cached views Source: https://github.com/gustavinho/laravel-views/blob/master/README.md After upgrading to version 2.3, the blade directives have changed. Clear the cached views to ensure the changes are applied correctly. ```bash php artisan view:clear ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.