PHP code example of fnematov / scramble-laravel-data
1. Go to this page and download the library: Download fnematov/scramble-laravel-data 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/ */
fnematov / scramble-laravel-data example snippets
use Spatie\LaravelData\Attributes\Validation\{Email, Max};
use Spatie\LaravelData\Data;
class CreateUserData extends Data
{
public function __construct(
public string $name,
#[Email]
public string $email,
#[Max(500)]
public ?string $bio = null,
) {}
}
public function store(CreateUserData $data): UserData
{
// ...
}
use Fnematov\ScrambleLaravelData\Support\LaravelData\HasPaginatedResponse;
use Spatie\LaravelData\Data;
class UserData extends Data
{
use HasPaginatedResponse;
public function __construct(
public int $id,
public string $name,
) {}
}
public function index()
{
return UserData::paginated(User::query()->paginate());
}
public function all()
{
return UserData::list(User::all());
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.