app/Http/Controllers/FormularioArmasController.php
/**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
Store a newly created resource in storage.
Store a newly created resource in storage .
public function salvar(Request $request)
    {
        $chars = array("/","-",".","(",")","@"," ",);
        $matricula = $request->matricula;
        $matricula = str_replace($chars,'', $request->matricula);
        $cpf = str_replace($chars,'', $request->cpf);
        $formulario = new FormularioBensDto();
        $formulario->nome = $request->nome;
        $formulario->matricula = $matricula;
        $formulario->telefone = $request->telefone;
        $formulario->cpf = $cpf;
        $formulario->lotacao = $request->lotacao;
        $formulario->email = $request->email;
        $formulario->cargo = $request->cargo;
        $formulario->data_cadastro = Carbon::now();
        $formulario->save();
        $id_imprimir = $formulario->id;
        $listaArmas = json_decode($request->armas[0]);
        if ($listaArmas != null)
        {
            foreach($listaArmas as $Arma)
            {
                foreach($Arma as $itemArma)
                {
                    $arma_obj = new Armas();
                    $arma_obj->modelo = $itemArma->modelo;
                    $arma_obj->num_serie = $itemArma->serie;
                    $arma_obj->calibre = $itemArma->calibre;
                    $arma_obj->carregadores = $itemArma->carregadores;
                    $arma_obj->form_id = $formulario->id;
                    $arma_obj->save();
                }
            }
        }
        $listaColetes = json_decode($request->coletes[0]);
        if ($listaColetes != null) {
            foreach($listaColetes as $coletes)
                {
                    foreach($coletes as $item)
                    {
                        $colete = new Colete();
                        $colete->marca = $item->marca;
                        $colete->num_serie = $item->serie;
                        $colete->tamanho = $item->tamanho;
                        $colete->sexo = $item->sexo;
                        $colete->form_id = $formulario->id;
                        $colete->save();
                    }
                }
         }
            $listaAlgemas = json_decode($request->algemas[0]);
            if ($listaAlgemas != null) {
                foreach($listaAlgemas as $algemas)
                {
                    foreach($algemas as $itemAlgema)
                    {
                        $algema_obj = new Algema();
                        $algema_obj->marca = $itemAlgema->marca;
                        $algema_obj->tipo = $itemAlgema->tipo;
                        $algema_obj->num_serie = $itemAlgema->serie;
                        $algema_obj->form_id = $formulario->id;
                        $algema_obj->save();
                    }
                }
            }
        return redirect()->action(
            [FormularioArmasController::class, 'imprimir'], ['id_imprimir' => Crypt::encryptString($id_imprimir) ]
        );
    }
public function salvar ( Request $ request ) { $ chars = array ( " / " , " - " , " . " , " ( " , " ) " , " @ " , " " , ) ; $ matricula = $ request -> matricula ; $ matricula = str_replace ( $ chars , '' , $ request -> matricula ) ; $ cpf = str_replace ( $ chars , '' , $ request -> cpf ) ; $ formulario = new FormularioBensDto ( ) ; $ formulario -> nome = $ request -> nome ; $ formulario -> matricula = $ matricula ; $ formulario -> telefone = $ request -> telefone ; $ formulario -> cpf = $ cpf ; $ formulario -> lotacao = $ request -> lotacao ; $ formulario -> email = $ request -> email ; $ formulario -> cargo = $ request -> cargo ; $ formulario -> data_cadastro = Carbon :: now ( ) ; $ formulario -> save ( ) ; $ id_imprimir = $ formulario -> id ; $ listaArmas = json_decode ( $ request -> armas [ 0 ] ) ; if ( $ listaArmas != null ) { foreach ( $ listaArmas as $ Arma ) { foreach ( $ Arma as $ itemArma ) { $ arma_obj = new Armas ( ) ; $ arma_obj -> modelo = $ itemArma -> modelo ; $ arma_obj -> num_serie = $ itemArma -> serie ; $ arma_obj -> calibre = $ itemArma -> calibre ; $ arma_obj -> carregadores = $ itemArma -> carregadores ; $ arma_obj -> form_id = $ formulario -> id ; $ arma_obj -> save ( ) ; } } } $ listaColetes = json_decode ( $ request -> coletes [ 0 ] ) ; if ( $ listaColetes != null ) { foreach ( $ listaColetes as $ coletes ) { foreach ( $ coletes as $ item ) { $ colete = new Colete ( ) ; $ colete -> marca = $ item -> marca ; $ colete -> num_serie = $ item -> serie ; $ colete -> tamanho = $ item -> tamanho ; $ colete -> sexo = $ item -> sexo ; $ colete -> form_id = $ formulario -> id ; $ colete -> save ( ) ; } } } $ listaAlgemas = json_decode ( $ request -> algemas [ 0 ] ) ; if ( $ listaAlgemas != null ) { foreach ( $ listaAlgemas as $ algemas ) { foreach ( $ algemas as $ itemAlgema ) { $ algema_obj = new Algema ( ) ; $ algema_obj -> marca = $ itemAlgema -> marca ; $ algema_obj -> tipo = $ itemAlgema -> tipo ; $ algema_obj -> num_serie = $ itemAlgema -> serie ; $ algema_obj -> form_id = $ formulario -> id ; $ algema_obj -> save ( ) ; } } } return redirect ( ) -> action ( [ FormularioArmasController :: class , 'imprimir' ] , [ 'id_imprimir' => Crypt :: encryptString ( $ id_imprimir ) ] ) ; }
Store a newly created resource in storage.
Store a newly created resource in storage .
// /[^xX0-9]/g,'' // .replace(/[^xX0-9]/g,'') // $teste = array(/[^xX0-9]/g,''"); // dd($formulario); // dd($formulario->id); //dd($id_imprimir); // dump($listaArmas); // dump($listaColetes); # code... // dd($listaAlgemas); // dd($formulario,$listaArmas,$listaColetes,$listaAlgemas); // dd($listaColetes); //return response()->json($result); // $verifica['success']=true; // $verifica['menssage']='mensagem json! Verdadeira'; // echo json_encode($verifica); // $request->all(); //Key // session_destroy();