You can use the Accessors & Mutators of Larable, where field formatting is done directly model
:
I will propose an example, because in your question there is no model
and it would be important to have and the table layout because of the fields, but I’m going to 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);
}
}
Inside the table noticias
, has a field with the name title, I need the display to be all capitalized, so create a mutation method get
which automatically does the specific field conversion title.
Standards:
get
+ field name + Attribute($value)
if the field is separate for underscore
as an example primeiro_nome
would be:
public function getPrimeiroNomeAttribute($value)
that is, the initials in capital letters between underscore
There is also the set
that would be a change of the value sent, also putting effects and significant changes in the value of this field, reflecting all this change in its table.
Standards:
set
+ field name + Attribute($value)
Code with the same field titulo
table noticias
(fictional example):
public function setTituloAttribute($value)
{
$this->attributes['titulo'] = $value;
}
Complete code fictional example Model 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;
}
}
put all the code related to the error, and the problem? because it has errors and problems in your inquiry?
model
,tabela e seu layout
are welcome, I even imagine the solution, but, I need to visualize where to put !– novic