Advanced-methods Last updated: 2023-08-27

Here we will put all the additional functions through which to change the state of each element

Let's take logically the text element as an example

We know that this element has the following 

placeholder , readonly disabled 

So how does it affect this attributes?

1 - placeholder

text()->make('User Name','name')->placeholder('Write Your User Name Here')

2 - readonly

text()->make('User Name','name')->readonly()

3 - disabled

text()->make('User Name','name')->disabled()

These methods can be used dynamically

for example

// boolean
->disabled(false) // or
->disabled(function(){
 return $this->id == 1;
})

// boolean
->readonly(false)// or
->readonly(function(){
 return $this->id == 1;
})

// just text
->placeholder('your text')// or
->placeholder(function(){
 return 'your text';
})


// add help text under input or html
->help('your text')// or
->help(function(){
 return 'your text';
})


// text align in input
->textAlign('left')// left,center,right
->textAlign(function(){
 return 'left';
})

 

With  textarea you can specify cols and rows  

textarea()->make('add content','content')->cols(10)->rows(50)

 

checkbox() input

checkbox()	
	->make('Allow', 'allow')
		->default('On') // auto checked in create page
// you can add boolean value 1,2 | on,off , yes,no etc..		
		->trueVal('On') // true value 
		->falseVal('Off') // false value 

 

dropdown select

select()->make('Account Type','account_type') // you can use disabled() with this element
->options([
'user'=>'User',
'admin'=>'admin',
])
->selected('user') //  select default value 

// or with dynamic values
select()->make('Category','category_id')
->options(Category::pluck('name','id'))
->selected(1) // select default value 

 

 

 

Upload  file mixed Files or by MimeType

fileUpload()	
		->make('File', 'file')
		->accept('image/png', 'image/jpeg') // mimeTypes 
		->deletable(false) // disable delete button in show or update page
		->disableDownloadButton() // disable download button in show or update page

 

 

Upload  image  

image()->make('Image', 'image')
		->deletable(false) // true|false
		->disableDownloadButton()
		->disablePreviewButton() // disable perview modal to show image
	   ->whenStore(function ($model) {
	    // when store can handel one or more values with multiple column
		// using $model parameter
	 		$file = url('storage/users/'.$model->id.'/'.$model->name);
	 		return [
	 			'image' => $file,
	 		];
	 	})
		->path('users/{id}') // static path or dynamic with $model
	// ->path(function ($model) {
	// 		return 'users/'.$model->id.'/'.$model->name;
	// 	})
		->accept('image/png', 'image/jpeg')

 

upload video

this input can handling your media streaming videos based on https://videojs.com library with five themes

	video()	->make('video', 'video') // you can use path and whenStore , whenUpdate method
		->deletable(false)
		->disableDownloadButton() // true | false
		->disablePreviewButton() // true | false
		->playerTheme('forest')//sea,forest,city,fantasy
		->accept('video/*') // mimeTypes

 

upload audio

 audio()->make('Audio', 'audio')
		->deletable(false) // true | false
		->disableDownloadButton() // true | false
		->disablePreviewButton() // true | false
		->accept('audio/*') // mimeTypes

 

 color & tel & url

 color()->make('Color', 'color') // you can use help & placeholder , whenstore , whenUpdate
 tel()->make('Mobile', 'mobile') // same  
 uri()	->make('URL', 'url') // same  

 

 

 ckeditor5 Editor nested textarea based On  https://ckeditor.com

// you can use help & placeholder , whenstore , whenUpdate
 ckeditor()->make('content', 'content') 

 

 

 values methods 

text()->make('User Name','name')->value('some value') 
// or dynamic
->value(function($model){
//return 'some text '; 
return $model->columnName; // with update or $this->columnName;
})


// or specify when Create or Store data
text()->make('User Name','name')->valueWhenCreate('some value') 
// or dynamic
->valueWhenCreate(function($model){
//return 'some text '; 
return $model->columnName; // with update or $this->columnName;
})


// or specify when Edit or Update data
text()->make('User Name','name')->valueWhenUpdate('some value') 
// or dynamic
->valueWhenUpdate(function($model){
//return 'some text '; 
return $model->columnName; // with update or $this->columnName;
})

 

 

 whenStore or whenUpdate strategy   

you can use all functionality from current model with whenStore or whenUpdate to get more benefits 

like makeVisible('password',etc…) Column for example password 

   		->whenStore(function(){
                return bcrypt(request('password'));
            })  ->whenUpdate(function(){
                return !empty(request('password'))? bcrypt(request('password')):$this->makeVisible('password')->password;
            })

so you can call any available method from model whenStore or Update Value