1. Go to this page and download the library: Download wsssoftware/laraveltoolkit 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/ */
wsssoftware / laraveltoolkit example snippets
use LaravelToolkit\Facades\Flash;
use LaravelToolkit\Flash\Severity;
// You can use this severities
Flash::success('Success Test');
Flash::info('Info Test');
Flash::warn('Warn Test');
Flash::error('Error Test');
Flash::secondary('Secondary Test');
Flash::contrast('Contrast Test');
// You can pass a summary
Flash::success('Message detail', 'Success!');
// You can mark flash as closable or unclosable
Flash::success('Success Test closable')->closable();
Flash::success('Success Test unclosable')->unclosable();
// You can pass a lifetime in seconds to your flash
Flash::success('Success Test with life')->withLife(2000);
// Your message can belong to another group (renders in another primevue group)
Flash::success('Success Test in other group')->withGroup('foo_bar');
// You can test flash using
Flash::assertFlashed(Severity::SUCCESS, 'User saved!');
Flash::assertNotFlashed(Severity::SUCCESS, 'User saved!');
use Illuminate\Http\Request;
use Inertia\Response;
use LaravelToolkit\Facades\SEO;
use LaravelToolkit\SEO\Image;
class ExampleController
{
/**
* Handle the incoming request.
*/
public function __invoke(Request $request): Response
{
SEO::withTitle('Client Orders')
->withoutDescription('A long description of this page')
->withCanonical('https://foo.com')
->withOpenGraphImage(new Image('public', 'seo.webp'))
->withTwitterCardImage(new Image('public', 'seo.webp', 'alt title'));
// If you want to remove a property you can call methods prefixed with `without`
SEO::withoutOpenGraphImage();
return Inertia::render('Example');
}
}
use LaravelToolkit\Facades\SEO;
// Returns true if request agent is a crawler
SEO::isCrawler();
// or
SEO::isCrawler('user agent');
// Transform a human string into a pretty wrote url string
SEO::friendlyUrlString('A example of string!')
// returns 'a-example-of-string'
use App\Models\User;
use LaravelToolkit\Facades\Sitemap;
// You can pass only url
Sitemap::addUrl(route('index'));
// Or a complete info (url, last modified, change frequency and priority
Sitemap::addUrl(route('login'), today()->subDay(), ChangeFrequency::DAILY, 0.5);
// You can interact with queries or collections
Sitemap::fromQuery(User::query(), function (User $user) {
Sitemap::addUrl(route('index.user', $user->id), $user->created_at);
});
Sitemap::fromCollection(collect([10, 53, 29]), function (User $user) {
Sitemap::addUrl(route('index.user', $user->id));
});
// A group of sitemaps that only will return if domain matches. Other registries out from this group will be ignored
Sitemap::domain('abc.dev.test', function () {
Sitemap::addUrl(route('login'));
});
// An index group used for huge sitemaps with more than 50k rows or 50MB
Sitemap::index('users', function () {
Sitemap::fromQuery(User::query(), function (User $user) {
Sitemap::addUrl(route('index.user', $user->id), $user->created_at);
});
});
// will be accessible on `route('lt.sitemap_group', "users");`
// then to put this index on main sitemap use:
Sitemap::addIndex('users');