PHP code example of jand3v / laravel-opinionated-essentials
1. Go to this page and download the library: Download jand3v/laravel-opinionated-essentials 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/ */
jand3v / laravel-opinionated-essentials example snippets
$user->created_at->addDay(); // returns a new instance, original unchanged
// Use the default password rule in your form requests
'password' => ['
declare(strict_types=1);
namespace App\Actions;
final readonly class PlaceOrderAction
{
public function __construct() {}
public function execute(): void
{
//
}
}
// app/Actions/PlaceOrderAction.php
final readonly class PlaceOrderAction
{
public function __construct() {}
public function execute(PlaceOrderData $data): void
{
//
}
}
// app/DTOs/PlaceOrderData.php
final readonly class PlaceOrderData
{
use MapsFromArray;
public function __construct(
// Add your properties here
) {}
}
use Jand3v\OpinionatedEssentials\Dto\Attributes\MapFrom;
use Jand3v\OpinionatedEssentials\Dto\Concerns\MapsFromArray;
final readonly class PlaceOrderData
{
use MapsFromArray;
public function __construct(
public int $customerId,
public string $customerName, // mapped from 'customer_name'
#[MapFrom('order_total')]
public int $totalAmount, // mapped from 'order_total'
public ?string $note = null, // optional, defaults to null
) {}
}
public function store(Request $request): Response
{
$data = PlaceOrderData::from($request->validated());
// $data->customerId, $data->customerName, $data->totalAmount
}