0
I need to include a string data in my database table that I will take for input, which in turn is an array. Follow the form so you can see how it is.
<div class="form-inline col-md-12">
<div class="form-group col-md-4">
<label for="create-contest-theme#1" class="control-label">1º Tema: </label>
<div class="input-group">
<input type="text" name="theme[]" id="create-contest-theme#1" class="form-control">
</div>
</div>
<div class="form-group col-md-4">
<label for="create-contest-theme#2" class="control-label">2º Tema: </label>
<div class="input-group">
<input type="text" name="theme[]" id="create-contest-theme#2" class="form-control">
</div>
</div>
<div class="form-group col-md-4">
<label for="create-contest-theme#3" class="control-label">3º Tema: </label>
<div class="input-group">
<input type="text" name="theme[]" id="create-contest-theme#3" class="form-control">
</div>
</div>
</div>
The action of this form points to my controller’s create function:
public function create(CreateRequest $request){
$inputs = $request->except('_token');
$contest = Contest::create($inputs);
return $contest;
}
A model Constest
class Contest extends Model
{
protected $table = 'contests';
}
And my big question is: How to treat this input theme
to be a string when it is stored?
That’s not what I want to do, What happens is this: I have 3 inputs with the same
name=theme[]
, which will give me an array. But to store this information in the database I wanted to turn this array into a string with a delimiter usingìmplode
for example:theme[0] = ação, theme[1]= drama
i want this to be a string equal to "action,drama"– Guilherme Tel Souza Ferreira
That’s why I signaled that information was missing on your question. It is necessary to elaborate better so that you can receive help more quickly and accurately.
– Igor Albuquerque