> For the complete documentation index, see [llms.txt](https://queents.gitbook.io/vilt/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://queents.gitbook.io/vilt/resource/hooks.md).

# Hooks

he resource class has a lot of hooks to handle the data on every method.

### Index Hooks

```php
public function beforeIndex(Request $request): Request
{
    return $request;
}
```

```php
public function beforeIndexQuery($query, Request $request, array $rows): void {}
```

```php
public function beforeIndexQueryAPI($query, Request $request,array $rows): void {}
```

```php
public function afterIndexQuery($query, Request $request, array $rows): void {}
```

```php
public function afterIndexQueryAPI($query, Request $request, array $rows): void {}
```

```php
public function beforeIndexAPI(Request $request): Request 
```

```php
{
   return $request;
}
```

```php
public function afterIndex(LengthAwarePaginator $data,Request $request): void {}
```

```php
public function afterIndexAPI(LengthAwarePaginator $data,Request $request): void {}
```

### Store Hooks

```php
public function beforeStore(Request $request): Request
{
   return $request;
}
```

```php
public function beforeStoreAPI(Request $request): Request
```

```php
{
   return $request;
}
```

```php
public function afterStore(Request $request, $record): void {}
```

```php
public function afterStoreAPI(Request $request, $record): void {}
```

### Show Hooks

```php
public function beforeShow(Request $request, $record)
{
   return $record;
}
```

```php
public function beforeShowQuery($query, Request $request, array $rows): void {}
```

```php
public function beforeShowQueryAPI($query, Request $request,array $rows): void {}
```

```php
public function afterShowQuery($record, Request $request, array $rows): void {}
```

```php
public function afterShowQueryAPI($record, Request $request, array $rows): void {}
```

```php
public function beforeShowAPI(Request $request, $record)
{
   return $record;
}
```

```php
public function afterShow(Request $request, $record): void {}
```

```php
public function afterShowAPI(Request $request, $record): void {}
```

### Update Hooks

```php
public function beforeUpdate(Request $request, $record): Request
{
   return $request;
}
```

```
public function beforeUpdateAPI(Request $request, $record): Request
```

```php
{
   return $request;
}
```

```php
public function afterUpdate(Request $request, $record): void {}
```

```
public function afterUpdateAPI(Request $request, $record): void {}
```

### Destroy Hooks

```php
public function afterDestroy(Request $request, $id): void {}
```

```php
public function beforeDestroy(Request $request, $record): Request
{
   return $request;
}
```

### Bulk Hooks

```php
public function beforeBulk(Request $request): Request
{
   return $request;
}
```

```php
public function afterBulk(Request $request): void {}
```

### Export Hooks

```php
public function beforeExport(Request $request, $record): Request
{
   return $request;
}
```

```php
public function afterExport(Request $request, $record): void {}
```

### Import Hooks

```php
public function beforeImport(Request $request, $record): Request
{
   return $request;
}
```

```php
public function afterImport(Request $request, $record): void {}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://queents.gitbook.io/vilt/resource/hooks.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
