PHP code example of a2workspace / laravel-model-builder
1. Go to this page and download the library: Download a2workspace/laravel-model-builder 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/ */
a2workspace / laravel-model-builder example snippets
namespace App\ModelBuilders;
use App\Models\Product;
use A2Workspace\ModelBuilder\ModelBuilder;
class ProductBuilder extends ModelBuilder
{
public function make()
{
$product = new Product;
$product->name = $this->name;
$product->price = $this->price;
// ...
return $product;
}
public function rules()
{
return [
'name' => '
class ProductBuilder extends ModelBuilder
{
public function make(): Product
{
$product = new Product;
$product->name = $this->name;
$product->price = $this->price;
// ...
return $product;
}
}
class ProductBuilder extends ModelBuilder
{
public function setPriceAttribute($value)
{
if (0 >= $value) {
throw new InvalidArgumentException('價格必須大於 0');
}
$this->attributes['price'] = $value;
}
}
class ProductBuilder extends ModelBuilder
{
public function rules(): array
{
return [
// ...
];
}
public function messages(): array
{
return [
// ...
];
}
}
bash
php artisan make:builder ProductBuilder
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.