<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
karlos3098 / laravel-primevue-table-service example snippets
composer
namespace App\Services;
use App\Http\Resources\MessageResource;
use App\Models\Message;
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
use Karlos3098\LaravelPrimevueTableService\Enum\TableCalendarDateFormat;
use Karlos3098\LaravelPrimevueTableService\Services\BaseService;
use Karlos3098\LaravelPrimevueTableService\Services\Columns\TableCalendarColumn;
use Karlos3098\LaravelPrimevueTableService\Services\Columns\TableTextColumn;
use Karlos3098\LaravelPrimevueTableService\Services\TableService;
final class MessageService extends BaseService
{
public function __construct(
protected Message $messageModel,
) {
}
/**
* @throws \Exception
*/
public function findAll(): AnonymousResourceCollection
{
return $this->fetchData(
MessageResource::class,
$this->messageModel,
new TableService(
globalFilterColumns: ['text'],
columns: [
'text' => new TableTextColumn(
placeholder: 'Search by text'
),
'contact' => new TableTextColumn(
placeholder: 'Message contact name',
queryPaths: [
'senderPhoneNumber.phone_number', 'senderContact.name',
'receivers.phoneNumber.phone_number', 'receivers.contact.name',
],
),
'date' => new TableCalendarColumn(
format: TableCalendarDateFormat::YMD,
placeholder: 'Search by created at',
sortable: true,
queryPaths: ['created_at'],
sortPath: 'created_at',
),
'type' => new TableDropdownColumn(
placeholder: 'Select Message Type',
options: [
new TableDropdownOptionTag(
label: 'Incomming',
query: fn ($query) => $query->where('incomming', true),
severity: TagSeverity::SUCCESS
),
new TableDropdownOptionTag(
label: 'Outgoing',
query: fn ($query) => $query->where('incomming', false),
severity: TagSeverity::INFO
),
]
),
],
rowsPerPage: [30, 100],
propName: 'messages',
)
);
}
}
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Services\MessageService;
use Illuminate\Http\Request;
use Inertia\Inertia;
class MessageController extends Controller
{
public function __construct(
protected MessageService $messageService,
) {
}
public function index()
{
return Inertia::render('Messages/Index', [
'messages' => $this->messageService->findAll(),
]);
}
}
sh
php artisan vendor:publish --provider="Karlos3098\\LaravelPrimevueTableService\\Providers\\LaravelPrimevueTableServiceProvider"
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.