1
I have a column with the name "code". Is it possible to complete it using the same method as the form? If yes, how can I implement this in my code.
Method that receives the form and inserts it into the bank.
public function insert(ManifestationFormRequest $request)
{
//armazena form em dataForm
$dataForm = $request->except('_token');
//Insere Formulário no Banco
$insert = $this->manifestation->insert($dataForm);
//verifica se existe arquivo e se é válido
if($request->hasFile('upload') && $request->file('upload')->isValid())
{
//Define default para variavel que vai conter nome do arquivo.
$fileName = null;
//Define nome aleatorio baseado no timestamp atual.
$name = uniqid(date('dmYHis'));
//Pega extensao do arquivo original e armazena em $ext.
$ext = $request->upload->getClientOriginalExtension();
//Define nome do arquivo + extensão.
$fileName = "{$name}.{$ext}";
//Armazena arquivo em Storage/app/uploads e renomeia.
$upload = $request->upload->storeAs('uploads', $fileName);
}
Alert::success('Enviado...', 'Obrigado pela sua contribuição');
return redirect()->route('index');
}
Migrate
Schema::create('manifestations', function (Blueprint $table) {
$table->increments('id');
$table->string('code', 64)->nullable();
$table->string('name', 64);
$table->string('email', 100);
$table->string('rg', 20)->nullable();
$table->string('cpf', 14)->nullable();
$table->string('address', 150);
$table->string('cep', 10);
$table->string('city', 36);
$table->string('state', 8);
$table->string('phone', 16);
$table->string('fax', 16)->nullable();
$table->integer('FK_cat_id')->unsigned();
$table->string('upload')->nullable();
$table->string('manifestation', 800);
$table->enum('response', [
'Email',
'Telefone',
'Fax',
'Não Informado'
]);
$table->timestamps();
Code column where?
– novic
Oops! Updated with my migrate.
– João
$dataForm['code'] ='value' this solves if it is a manual fill
– novic
$code = hexdec(uniqid());
returns a decimal value with 13 digits. I want the newly created ID concatenating with$code
entered in the code field of the same record. ps: sorry if I wasn’t clear– João
Take the result of the Insert and assign the value to the code the way you want and call the save() method. Example: $Insert->code = $code; $Insert->save();
– novic
What I want to put together is
increments('id');
with$code
and put the result in the field code ta table.– João
You need to read the documentation, do this... I created a minimal example in response take a look
– novic
Thank you so much for the effort @Virgilionovic. I have been reading, but I haven’t been able to subtract very well what I need. I will analyze your response and make the implementation. Again my thanks!
– João