🪝Hooks

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

Index Hooks

public function beforeIndex(Request $request): Request
{
    return $request;
}
public function beforeIndexQuery($query, Request $request, array $rows): void {}
public function beforeIndexQueryAPI($query, Request $request,array $rows): void {}
public function afterIndexQuery($query, Request $request, array $rows): void {}
public function afterIndexQueryAPI($query, Request $request, array $rows): void {}
public function beforeIndexAPI(Request $request): Request 
{
   return $request;
}
public function afterIndex(LengthAwarePaginator $data,Request $request): void {}
public function afterIndexAPI(LengthAwarePaginator $data,Request $request): void {}

Store Hooks

public function beforeStore(Request $request): Request
{
   return $request;
}
public function beforeStoreAPI(Request $request): Request
{
   return $request;
}
public function afterStore(Request $request, $record): void {}
public function afterStoreAPI(Request $request, $record): void {}

Show Hooks

public function beforeShow(Request $request, $record)
{
   return $record;
}
public function beforeShowQuery($query, Request $request, array $rows): void {}
public function beforeShowQueryAPI($query, Request $request,array $rows): void {}
public function afterShowQuery($record, Request $request, array $rows): void {}
public function afterShowQueryAPI($record, Request $request, array $rows): void {}
public function beforeShowAPI(Request $request, $record)
{
   return $record;
}
public function afterShow(Request $request, $record): void {}
public function afterShowAPI(Request $request, $record): void {}

Update Hooks

public function beforeUpdate(Request $request, $record): Request
{
   return $request;
}
public function beforeUpdateAPI(Request $request, $record): Request
{
   return $request;
}
public function afterUpdate(Request $request, $record): void {}
public function afterUpdateAPI(Request $request, $record): void {}

Destroy Hooks

public function afterDestroy(Request $request, $id): void {}
public function beforeDestroy(Request $request, $record): Request
{
   return $request;
}

Bulk Hooks

public function beforeBulk(Request $request): Request
{
   return $request;
}
public function afterBulk(Request $request): void {}

Export Hooks

public function beforeExport(Request $request, $record): Request
{
   return $request;
}
public function afterExport(Request $request, $record): void {}

Import Hooks

public function beforeImport(Request $request, $record): Request
{
   return $request;
}
public function afterImport(Request $request, $record): void {}

Last updated