-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b8d533d
commit 56b550e
Showing
4 changed files
with
115 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
namespace Laraview\Libs\Elements; | ||
|
||
use Laraview\Console\Commands\LaraviewGenerateElement; | ||
use Laraview\Libs\Blueprints\ElementBlueprint; | ||
use Laraview\Libs\Elements\Generate\InputGeneration; | ||
use Laraview\Libs\Elements\Traits\Formats\FileBootstrap; | ||
|
||
abstract class File extends Text implements ElementBlueprint | ||
{ | ||
|
||
use FileBootstrap; | ||
|
||
/** | ||
* @return mixed|null|string | ||
*/ | ||
public static function humanReadableName() | ||
{ | ||
return 'File Element'; | ||
} | ||
|
||
/** | ||
* @param $region | ||
* @param LaraviewGenerateElement $console | ||
* @return mixed | ||
*/ | ||
public static function generate( $region, LaraviewGenerateElement $console ) | ||
{ | ||
$generator = new InputGeneration( $region, $console ); | ||
$generator->setStubPath( __DIR__ . '/../../../stubs/elements/file.stub' ); | ||
return $generator->create(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
namespace Laraview\Libs\Elements\Traits\Formats; | ||
|
||
trait FileBootstrap | ||
{ | ||
|
||
/** | ||
* @return string | ||
*/ | ||
protected function element() | ||
{ | ||
return sprintf( '<input type="file" name="%s" %s value="%s" />', | ||
$this->name, | ||
$this->attributes(), | ||
"{{ \${$this->valueKeyName()} }}" | ||
); | ||
} | ||
|
||
/** | ||
* @return void | ||
*/ | ||
protected function preRender() | ||
{ | ||
parent::preRender(); | ||
$this->attributes[ 'class' ] = trim( ( isset( $this->attributes[ 'class' ] ) ? $this->attributes[ 'class' ] : '' ) . ' form-control' ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
<?php | ||
|
||
namespace [NAMESPACE]; | ||
|
||
use Laraview\Libs\Blueprints\ElementBlueprint; | ||
use Laraview\Libs\Elements\File; | ||
|
||
class [CLASS_NAME] extends File implements ElementBlueprint | ||
{ | ||
|
||
/** | ||
* Name of input | ||
* @var string | ||
*/ | ||
protected $name = '[NAME]'; | ||
|
||
/** | ||
* Label text | ||
* @var string | ||
*/ | ||
protected $label = '[LABEL]'; | ||
|
||
/** | ||
* Input elements HTML attributes | ||
* @var array | ||
*/ | ||
protected $attributes = [ | ||
[ATTRIBUTES] | ||
]; | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function value() | ||
{ | ||
return old( $this->name ) ?: $this->data( "model.{$this->name}" ); | ||
} | ||
|
||
/** | ||
* @param $model | ||
* @param $request | ||
*/ | ||
public function receivePayload( $model, $request ) | ||
{ | ||
$model->{$this->name} = $request->input( $this->name ); | ||
} | ||
|
||
} |