You can use the Accessors & Mutators from laravel , where formatting of the field is made direct model
:
I'll propose an example , because in your question it does not have a model
and it would be important to have and table layout by cause of the fields, but, I will generalize with a basic example.
Example:
In your specific case the display factor is what you need:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Noticias extends Model
{
public function getTituloAttribute($value)
{
return strtoupper($value);
}
}
In the noticias
table, there is a field titled title . a % mutation method that automatically does the specific conversion of the title field.
Standards:
get
+ field name + get
If the field is separated by Attribute($value)
as an example underscore
would be:
public function getPrimeiroNomeAttribute($value)
that is, initials in upper case between primeiro_nome
It also has underscore
that would be a modification of change of sent value, also putting significant effects and changes on the value of this field, reflecting all this change in your table.
Standards:
set
+ field name + set
Code with the same field Attribute($value)
of table titulo
( dummy example ):
public function setTituloAttribute($value)
{
$this->attributes['titulo'] = $value;
}
Complete code dummy example noticias
:
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Noticias extends Model
{
// GET
public function getTituloAttribute($value)
{
return strtoupper($value);
}
// SET
public function setTituloAttribute($value)
{
$this->attributes['titulo'] = $value;
}
}