Page MenuHomePhorge

ObjectCreateCommand.php
No OneTemporary

Authored By
Unknown
Size
1 KB
Referenced Files
None
Subscribers
None

ObjectCreateCommand.php

<?php
namespace App\Console;
/**
* This abstract class provides a means to treat objects in our model using CRUD.
*/
abstract class ObjectCreateCommand extends ObjectCommand
{
public function __construct()
{
$this->description = "Create a {$this->objectName}";
$this->signature = sprintf(
"%s%s:create",
$this->commandPrefix ? $this->commandPrefix . ":" : "",
$this->objectName
);
$class = new $this->objectClass();
foreach ($class->getFillable() as $fillable) {
$this->signature .= " {--{$fillable}=}";
}
parent::__construct();
}
public function getProperties()
{
if (!empty($this->properties)) {
return $this->properties;
}
$class = new $this->objectClass();
$this->properties = [];
foreach ($class->getFillable() as $fillable) {
$this->properties[$fillable] = $this->option($fillable);
}
return $this->properties;
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$this->getProperties();
$class = new $this->objectClass();
$object = $this->objectClass::create($this->properties);
if ($object) {
$this->cacheRefresh($object);
$this->info($object->{$class->getKeyName()});
} else {
$this->error("Object could not be created.");
}
return $object;
}
}

File Metadata

Mime Type
text/x-php
Expires
Fri, Apr 24, 1:44 PM (1 d, 14 h ago)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
18793491
Default Alt Text
ObjectCreateCommand.php (1 KB)

Event Timeline