1. Go to this page and download the library: Download dancycodes/hyper 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/ */
dancycodes / hyper example snippets
// Laravel controller with Hyper's helpers
public function increment()
{
$count = signals('count', 0);
return hyper()->signals(['count' => $count + 1]);
}
public function store()
{
$validated = signals()->validate([
'name' => 'return hyper()->signals([
'name' => '',
'email' => '',
]);
}
public function destroy(User $user)
{
$user->delete();
$users = User::all();
return hyper()->view('users.list', compact('users'));
}
public function updateCart()
{
// Get specific signal with default value
$quantity = signals('quantity', 1);
// Check if signal exists
if (signals()->has('coupon')) {
$discount = signals('coupon');
}
// Get all signals
$allSignals = signals()->all();
// Get only specific signals
$data = signals()->only(['name', 'email']);
}
// Update single signal
return hyper()->signals(['count' => 5]);
// Update multiple signals
return hyper()->signals([
'count' => 5,
'message' => 'Updated!',
'errors' => []
]);
// Chain with other operations
return hyper()
->signals(['count' => 5])
->view('status', $data)
->js('console.log("Done")');
public function store()
{
$validated = signals()->validate([
'title' => 'ers'
]);
Post::create($validated);
return hyper()->signals(['message' => 'Post created']);
}
signals()->validate(
[
'email' => ' [
'email.unique' => 'This email is already registered.',
'password.min' => 'Password must be at least :min characters.'
],
[
'email' => 'email address',
'password' => 'password'
]
);
public function uploadAvatar()
{
signals()->validate([
'avatar' => '()->user()->update(['avatar' => $path]);
return hyper()->signals(['avatar' => $path]);
}
// Store with auto-generated filename
$path = signals()->store('avatar', 'avatars', 'public');
// Store and get public URL
$url = signals()->storeAsUrl('avatar', 'avatars', 'public');
// Store multiple files
$paths = signals()->storeMultiple([
'avatar' => 'avatars',
'banner' => 'banners'
], 'public');
public function destroy(Todo $todo)
{
$todo->delete();
$todos = Todo::all();
return hyper()
->fragment('todos.index', 'todo-list', compact('todos'))
->fragment('todos.index', 'todo-count', compact('todos'));
}
return hyper()->fragment('todos.index', 'todo-list', compact('todos'), [
'selector' => '#todo-list',
'mode' => 'outer' // Replace the element selected with all content
]);
// Navigate to a URL
return hyper()->navigate('/dashboard');
// Navigate with merged query parameters
return hyper()->navigateMerge('/products', ['category' => 'electronics']);
// Navigate keeping only specific parameters
return hyper()->navigateOnly('/products', ['search', 'sort']);
// Navigate excluding specific parameters
return hyper()->navigateExcept('/products', ['page']);
// Navigate with debounce
return hyper()->navigate('/search', ['debounce' => 300]);
// Standard Laravel redirect
return redirect('/dashboard');
// With flash data
return redirect('/dashboard')->with('success', 'User created');
public function liveMetrics()
{
return hyper()->stream(function($hyper) {
while (true) {
$metrics = $this->getLatestMetrics();
$hyper->signals(['metrics' => $metrics])
->fragment('dashboard', 'metrics-card', $metrics)
->send();
sleep(5);
}
});
}
use Dancycodes\Hyper\Routing\Attributes\Route;
#[Route(middleware: 'web')]
class PostController extends Controller
{
public function index()
{
// Auto-registered as GET /post
}
#[Route(method: 'post')]
public function store()
{
// Auto-registered as POST /post/store
}
#[Route(method: 'delete', uri: '/posts/{post}')]
public function destroy(Post $post)
{
// Custom URI with route model binding
}
}