Laravel views
Twitter Github
Examples

Table view examples

Error!
Success!
ID Avatar User Email Active Type Created
1 https://laravelviews.com/storage/avatar/51.png belal ddx daadadakk Writer 1 year ago
2 https://laravelviews.com/storage/avatar/3.png hello 2132tytyiu Admin 1 year ago
3 https://laravelviews.com/storage/avatar/49.png cdcsdc keykha asfd2 Admin 1 year ago
4 https://laravelviews.com/storage/avatar/19.png Just for testt adsf test Writer 1 year ago
5 https://laravelviews.com/storage/avatar/40.png test123 dwadwad Admin 1 year ago
6 https://laravelviews.com/storage/avatar/27.png sdsd test@test.test Admin 1 year ago
7 https://laravelviews.com/storage/avatar/64.png tesdasda javonte.kutch@example.comxfz Writer 1 year ago
8 https://laravelviews.com/storage/avatar/66.png Bande de iok qcollier@example.uk Admin 1 year ago
9 https://laravelviews.com/storage/avatar/27.png Brycen Schade celestinoprenner@example.net Admin 1 year ago
10 https://laravelviews.com/storage/avatar/14.png Mrs. Kassandra Stiedemann griffin.aufderha00r@example.net Admin 1 year ago
  
<?php

namespace App\Http\Livewire;

use App\Models\User;
use Illuminate\Database\Eloquent\Builder;
use LaravelViews\Facades\UI;
use LaravelViews\Views\TableView;

class UsersTableView extends TableView
{
    protected $paginate = 10;

    protected function repository()
    {
        return User::query();
    }

    /**
     * Sets the headers of the table as you want to be displayed
     *
     * @return array<string> Array of headers
     */
    public function headers(): array
    {
        return [
            'ID',
            'Avatar',
            'User',
            'Email',
            'Active',
            'Type',
            'Created'
        ];
    }

    /**
     * Sets the data to every cell of a single row
     *
     * @param $user Current model for each row
     */
    public function row(User $user): array
    {
        return [
            $user->id,
            UI::avatar(asset('storage/' . $user->avatar)),
            $user->name,
            $user->email,
            $user->active ? UI::icon('check', 'success') : '',
            ucfirst($user->type),
            $user->created_at->diffforHumans()
        ];
    }
}

  
Error!
Success!
Avatar Active Type
1 https://laravelviews.com/storage/avatar/51.png belal ddx daadadakk Writer 1 year ago
2 https://laravelviews.com/storage/avatar/3.png hello 2132tytyiu Admin 1 year ago
3 https://laravelviews.com/storage/avatar/49.png cdcsdc keykha asfd2 Admin 1 year ago
4 https://laravelviews.com/storage/avatar/19.png Just for testt adsf test Writer 1 year ago
5 https://laravelviews.com/storage/avatar/40.png test123 dwadwad Admin 1 year ago
6 https://laravelviews.com/storage/avatar/27.png sdsd test@test.test Admin 1 year ago
7 https://laravelviews.com/storage/avatar/64.png tesdasda javonte.kutch@example.comxfz Writer 1 year ago
8 https://laravelviews.com/storage/avatar/66.png Bande de iok qcollier@example.uk Admin 1 year ago
9 https://laravelviews.com/storage/avatar/27.png Brycen Schade celestinoprenner@example.net Admin 1 year ago
10 https://laravelviews.com/storage/avatar/14.png Mrs. Kassandra Stiedemann griffin.aufderha00r@example.net Admin 1 year ago
  
<?php

namespace App\Http\Livewire;

use DB;
use LaravelViews\Facades\Header;

class UsersWithSortColumnsTableView extends UsersTableView
{
    /**
     * Sets the headers of the table as you want to be displayed
     *
     * @return array<string> Array of headers
     */
    public function headers(): array
    {
        return [
            Header::title('ID')->sortBy('id'),
            'Avatar',
            Header::title('User')->sortBy('name'),
            Header::title('Email')->sortBy('email'),
            'Active',
            'Type',
            Header::title('Created')->sortBy('created_at')
        ];
    }
}

  
Error!
Success!
Users Active Filter
Users Type Filter
Users Created At Filter
Avatar Active Type
1 https://laravelviews.com/storage/avatar/51.png belal ddx daadadakk Writer 1 year ago
2 https://laravelviews.com/storage/avatar/3.png hello 2132tytyiu Admin 1 year ago
3 https://laravelviews.com/storage/avatar/49.png cdcsdc keykha asfd2 Admin 1 year ago
4 https://laravelviews.com/storage/avatar/19.png Just for testt adsf test Writer 1 year ago
5 https://laravelviews.com/storage/avatar/40.png test123 dwadwad Admin 1 year ago
6 https://laravelviews.com/storage/avatar/27.png sdsd test@test.test Admin 1 year ago
7 https://laravelviews.com/storage/avatar/64.png tesdasda javonte.kutch@example.comxfz Writer 1 year ago
8 https://laravelviews.com/storage/avatar/66.png Bande de iok qcollier@example.uk Admin 1 year ago
9 https://laravelviews.com/storage/avatar/27.png Brycen Schade celestinoprenner@example.net Admin 1 year ago
10 https://laravelviews.com/storage/avatar/14.png Mrs. Kassandra Stiedemann griffin.aufderha00r@example.net Admin 1 year ago
  
<?php

namespace App\Http\Livewire;

use App\Filters\UsersActiveFilter;
use App\Filters\UsersCreatedAtFilter;
use App\Filters\UsersTypeFilter;

class UsersWithFiltersTableView extends UsersWithSortColumnsTableView
{
    public $searchBy = ['name', 'email'];

    protected function filters()
    {
        return [
            new UsersActiveFilter,
            new UsersTypeFilter,
            new UsersCreatedAtFilter
        ];
    }
}

  
Error!
Success!
Users Active Filter
Users Type Filter
Users Created At Filter
Avatar Active Type
1 https://laravelviews.com/storage/avatar/51.png belal ddx daadadakk Writer 1 year ago
2 https://laravelviews.com/storage/avatar/3.png hello 2132tytyiu Admin 1 year ago
3 https://laravelviews.com/storage/avatar/49.png cdcsdc keykha asfd2 Admin 1 year ago
4 https://laravelviews.com/storage/avatar/19.png Just for testt adsf test Writer 1 year ago
5 https://laravelviews.com/storage/avatar/40.png test123 dwadwad Admin 1 year ago
6 https://laravelviews.com/storage/avatar/27.png sdsd test@test.test Admin 1 year ago
7 https://laravelviews.com/storage/avatar/64.png tesdasda javonte.kutch@example.comxfz Writer 1 year ago
8 https://laravelviews.com/storage/avatar/66.png Bande de iok qcollier@example.uk Admin 1 year ago
9 https://laravelviews.com/storage/avatar/27.png Brycen Schade celestinoprenner@example.net Admin 1 year ago
10 https://laravelviews.com/storage/avatar/14.png Mrs. Kassandra Stiedemann griffin.aufderha00r@example.net Admin 1 year ago
  
<?php

namespace App\Http\Livewire;

use App\Actions\ChangeUserAsAdmin;
use App\Actions\ChangeUserAsWriter;
use App\Actions\ToggleUserAction;

class UsersWithActions extends UsersWithFiltersTableView
{
    protected function actionsByRow()
    {
        return [
            new ChangeUserAsAdmin,
            new ChangeUserAsWriter,
            new ToggleUserAction,
        ];
    }
}

  
Error!
Success!
Users Active Filter
Users Type Filter
Users Created At Filter
Avatar Active Type
1 https://laravelviews.com/storage/avatar/51.png belal ddx daadadakk Writer 1 year ago
2 https://laravelviews.com/storage/avatar/3.png hello 2132tytyiu Admin 1 year ago
3 https://laravelviews.com/storage/avatar/49.png cdcsdc keykha asfd2 Admin 1 year ago
4 https://laravelviews.com/storage/avatar/19.png Just for testt adsf test Writer 1 year ago
5 https://laravelviews.com/storage/avatar/40.png test123 dwadwad Admin 1 year ago
6 https://laravelviews.com/storage/avatar/27.png sdsd test@test.test Admin 1 year ago
7 https://laravelviews.com/storage/avatar/64.png tesdasda javonte.kutch@example.comxfz Writer 1 year ago
8 https://laravelviews.com/storage/avatar/66.png Bande de iok qcollier@example.uk Admin 1 year ago
9 https://laravelviews.com/storage/avatar/27.png Brycen Schade celestinoprenner@example.net Admin 1 year ago
10 https://laravelviews.com/storage/avatar/14.png Mrs. Kassandra Stiedemann griffin.aufderha00r@example.net Admin 1 year ago
  
<?php

namespace App\Http\Livewire;

use App\Actions\Bulk\ChangeUsersAsAdmin;
use App\Actions\Bulk\ChangeUsersAsWriter;

class UsersWithBulkActions extends UsersWithActions
{
    protected function bulkActions()
    {
        return [
            new ChangeUsersAsWriter,
            new ChangeUsersAsAdmin
        ];
    }
}

  
Error!
Success!
Users Active Filter
Users Type Filter
Users Created At Filter
Avatar Active Type
1 https://laravelviews.com/storage/avatar/51.png
belal ddx
daadadakk
Writer 1 year ago
2 https://laravelviews.com/storage/avatar/3.png
hello
2132tytyiu
Admin 1 year ago
3 https://laravelviews.com/storage/avatar/49.png
cdcsdc
keykha asfd2
Admin 1 year ago
4 https://laravelviews.com/storage/avatar/19.png
Just for testt adsf
test
Writer 1 year ago
5 https://laravelviews.com/storage/avatar/40.png
test123
dwadwad
Admin 1 year ago
6 https://laravelviews.com/storage/avatar/27.png
sdsd
test@test.test
Admin 1 year ago
7 https://laravelviews.com/storage/avatar/64.png
tesdasda
javonte.kutch@example.comxfz
Writer 1 year ago
8 https://laravelviews.com/storage/avatar/66.png
Bande de iok
qcollier@example.uk
Admin 1 year ago
9 https://laravelviews.com/storage/avatar/27.png
Brycen Schade
celestinoprenner@example.net
Admin 1 year ago
10 https://laravelviews.com/storage/avatar/14.png
Mrs. Kassandra Stiedemann
griffin.aufderha00r@example.net
Admin 1 year ago
  
<?php

namespace App\Http\Livewire\TableView;

use App\Http\Livewire\UsersWithBulkActions;
use App\Models\User;
use LaravelViews\Facades\UI;
use LaravelViews\Views\Traits\WithAlerts;

class UsersWithInlineEditing extends UsersWithBulkActions
{
    use WithAlerts;

    /**
     * Sets the data to every cell of a single row
     *
     * @param $user Current model for each row
     */
    public function row(User $user): array
    {
        return [
            $user->id,
            UI::avatar(asset('storage/' . $user->avatar)),
            UI::editable($user, 'name'),
            UI::editable($user, 'email'),
            $user->active ? UI::icon('check', 'success') : '',
            ucfirst($user->type),
            $user->created_at->diffforHumans()
        ];
    }

    /**
     * Method fired by the `editable` component, it
     * gets the model instance and a key value array
     * with the modified
     */
    public function update(User $user, $data)
    {
        $user->update(collect($data)->map(function ($value) {
            return strip_tags($value);
        })->toArray());
        $this->success();
    }
}