You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
namespace App\Tables\Formatters;
use Illuminate\Database\Eloquent\Model;
use Okipa\LaravelTable\Abstracts\AbstractFormatter;
class RowNrFormatter extends AbstractFormatter
{
public function format(Model $model, string $attribute): string
{
$currentPage = request()->input('page', 1); // Get current page from query parameter (default is 1)
$perPage = config('laravel-table.models.default.perPage'); // Get default number of items per page from the config
// Get the model's position in the current page results
$currentPosition = $model->newQuery()->where('id', '<=', $model->id)->count();
// Calculate the row number based on the current page and position
return ($currentPage - 1) * $perPage + $currentPosition;
}
}
request()->input('page', 1); and config('laravel-table.models.default.perPage'); simply doesn't work in Lararvel 10, how to crate row numbers? Maybe you can also give a formula for getting position that works everyway.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
In the next example
request()->input('page', 1); and config('laravel-table.models.default.perPage'); simply doesn't work in Lararvel 10, how to crate row numbers? Maybe you can also give a formula for getting position that works everyway.
Beta Was this translation helpful? Give feedback.
All reactions