PHP code example of ilaoniu / ziggy
1. Go to this page and download the library: Download ilaoniu/ziggy 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/ */
ilaoniu / ziggy example snippets
Route::get('posts', fn (Request $request) => /* ... */)->name('posts.index');
Route::get('posts/{post}', fn (Post $post) => /* ... */)->name('posts.show');
Route::get('venues/{venue}/events/{event}', fn (Venue $venue, Event $event) => /* ... */)
->name('venues.events.show');
Route::get('venues/{venue}/events/{event}', fn (Venue $venue, Event $event) => /* ... */)
->name('venues.events.show');
Route::get('{locale}/posts/{post}', fn (Post $post) => /* ... */)->name('posts.show');
// app/Http/Middleware/SetLocale.php
URL::defaults(['locale' => $request->user()->locale ?? 'de']);
// app/Models/Post.php
class Post extends Model
{
public function getRouteKeyName()
{
return 'slug';
}
}
Route::get('blog/{post}', function (Post $post) {
return view('posts.show', ['post' => $post]);
})->name('posts.show');
Route::get('authors/{author}/photos/{photo:uuid}', fn (Author $author, Photo $photo) => /* ... */)
->name('authors.photos.show');
// config/ziggy.php
return [
'only' => ['home', 'posts.index', 'posts.show'],
];
// config/ziggy.php
return [
'except' => ['_debugbar.*', 'horizon.*', 'admin.*'],
];
// config/ziggy.php
return [
'groups' => [
'admin' => ['admin.*', 'users.*'],
'author' => ['posts.*'],
],
];
@routes(nonce: 'your-nonce-here')
// routes/api.php
use Tighten\Ziggy\Ziggy;
Route::get('ziggy', fn () => response()->json(new Ziggy));
js
route('venues.events.show', {
venue: 1,
event: 2,
page: 5,
count: 10,
});
// 'https://ziggy.test/venues/1/events/2?page=5&count=10'
bash
php artisan ziggy:generate --types
bash
php artisan ziggy:generate
blade
{{-- authors.blade.php --}}
@routes('author')
blade
{{-- admin.blade.php --}}
@routes(['admin', 'author'])