1. Go to this page and download the library: Download meita/journal-guard 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/ */
meita / journal-guard example snippets
app('config')->set('journal-guard.resolvers.account', function ($line, $entry) {
// return model/array/bool to indicate active account
return $line->accountId() === 100 ? (object) ['is_active' => true] : null;
});
use Meita\JournalGuard\Traits\GuardsJournalEntries;
class JournalEntryService
{
use GuardsJournalEntries;
public function create(array $payload)
{
$this->guardJournalEntry($payload);
// ...persist entry
}
}
use Meita\JournalGuard\Contracts\RuleInterface;
use Meita\JournalGuard\DTO\JournalEntryDTO;
use Meita\JournalGuard\Exceptions\JournalValidationException;
class NoWeekendEntriesRule implements RuleInterface
{
public function validate(JournalEntryDTO $entry): void
{
if ($entry->date()->isWeekend()) {
throw new JournalValidationException([
['code' => 'weekend_block', 'message' => 'Weekend entries are not allowed.', 'path' => 'entry_date'],
]);
}
}
}
public function store(Request $request)
{
try {
JournalGuard::validate($request->all());
} catch (JournalValidationException $e) {
return back()->withErrors($e->errors());
}
// continue to save...
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.