1. Go to this page and download the library: Download paulohps/laravel-timeline library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
paulohps / laravel-timeline example snippets
namespace App\Timeline;
use Paulohps\Timeline\Events\TimelineEvent;
class Login extends TimelineEvent
{
public function label(): string
{
return __('Logged in');
}
}
namespace App\Timeline;
use Paulohps\Timeline\Events\TimelineEvent;
use Paulohps\Timeline\Models\TimelineEntry;
class OrderShipped extends TimelineEvent
{
// Stable storage/URL key. Defaults to the snake-cased class
// basename ('order_shipped'), so this override is optional.
public static function key(): string
{
return 'order_shipped';
}
public function label(): string
{
return __('Order shipped');
}
// Shown next to on/off switches on a settings page, if you build one.
public function description(): string
{
return __('When an order leaves the warehouse.');
}
// Inline HTML for the marker: an SVG, an emoji, an icon-font tag.
// Return null (the default) for a plain dot.
public function icon(): ?string
{
return '<svg viewBox="0 0 24 24">…</svg>';
}
// Marker color token → styled by .lt-item__marker--{token}.
// Shipped tokens: default, primary, success, info, warning, danger.
public function color(): string
{
return 'success';
}
// Secondary line under the title. Defaults to the request context
// captured at record time; subjectTitle() prefers the metadata
// 'title' snapshot and falls back to $entry->subject->title.
public function detail(TimelineEntry $entry): ?string
{
return $this->subjectTitle($entry);
}
// Dropdown links rendered on the entry (plain <details>, no JS).
public function navigation(TimelineEntry $entry): array
{
return [
['label' => __('View order'), 'href' => route('orders.show', $entry->subject_id)],
];
}
}
use Paulohps\Timeline\Facades\Timeline;
Timeline::register([
App\Timeline\Login::class,
App\Timeline\OrderShipped::class,
]);
use Paulohps\Timeline\Concerns\HasTimeline;
class User extends Authenticatable
{
use HasTimeline;
}
// Via the trait — accepts an instance, class name or registered key:
$user->recordTimelineEvent(new Login);
$user->recordTimelineEvent(OrderShipped::class, $order, ['title' => $order->number]);
$user->recordTimelineEvent('order_shipped', $order);
// Via the event itself:
(new OrderShipped)->record($user, $order);
// Via the facade:
Timeline::record($user, 'login');
$user->timelineEntries; // MorphMany of TimelineEntry
$user->recordTimelineEvent('order_shipped', $order, [
'title' => $order->number, // snapshot used by subjectTitle()
'carrier' => 'DHL',
]);
use Paulohps\Timeline\Models\TimelineEntry;
TimelineEntry::forCauser($user)->ofType('login')->count();
TimelineEntry::forCauser($team)->ofType(['login', 'logout'])->latest()->get();
$user->timelineEntries()->ofType('login')->first(); // last login
public function render(TimelineEntry $entry): View
{
return view('timeline.order-shipped', ['entry' => $entry]);
}