<commit_before><?php

namespace App\Http\Controllers;

use App\Cliente;
use App\Endereco;
use Illuminate\Http\Request;

class ClienteController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $cliente = Cliente::with('Endereco')->get()->toJson();

        return $cliente;
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $request->validate([
            'nome' => 'required|max:150',
            'email' => 'required|max:120',
            'cpf' => 'required|max:11',
        ]);

        // $cliente = Cliente::with('Endereco')->get();

        $cliente = $request->all();
        $endereco = Endereco::create($cliente['endereco']);

        Cliente::create([
            "nome" => $cliente['nome'],
            "email" => $cliente['email'],
            "cpf" => $cliente['cpf'],
            "saldo" => $cliente['saldo'],
            "endereco_id" => $endereco->id,
        ]);

        return response(["status" => "Cadastrado com sucesso"], 200);

    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        return Cliente::with('Endereco')->find($id);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {

        $cliente = $request->all();

        $reg = Cliente::with('endereco')->where('id', '=', $id)->first();


        if(isset($cliente['endereco'])){
             $reg->endereco->update($cliente['endereco']);
        }

        $reg->update($cliente);

        return response(["status" => "Alterado  com sucesso"], 200);

    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $reg = Cliente::find($id);

        $reg->delete();

        return response(["status" => "Removido com sucesso"], 200);
    }
}
<commit_msg>fix update<commit_after><?php

namespace App\Http\Controllers;

use App\Cliente;
use App\Endereco;
use Illuminate\Http\Request;

class ClienteController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
        $cliente = Cliente::with('Endereco')->get()->toJson();

        return $cliente;
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
        $request->validate([
            'nome' => 'required|max:150',
            'email' => 'required|max:120',
            'cpf' => 'required|max:11',
        ]);

        // $cliente = Cliente::with('Endereco')->get();

        $cliente = $request->all();
        $endereco = Endereco::create($cliente['endereco']);

        Cliente::create([
            "nome" => $cliente['nome'],
            "email" => $cliente['email'],
            "cpf" => $cliente['cpf'],
            "saldo" => $cliente['saldo'],
            "endereco_id" => $endereco->id,
        ]);

        return response(["status" => "Cadastrado com sucesso"], 200);

    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        return Cliente::with('Endereco')->find($id);
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {

        $cliente = $request->all();

        $reg = Cliente::with('endereco')->where('id', '=', $id)->first();


        if(isset($cliente['endereco'])){
             $reg->endereco->update($cliente['endereco']);
        }

        $reg->update($cliente);

        return response(["status" => "Alterado com sucesso"], 200);

    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function destroy($id)
    {
        $reg = Cliente::find($id);

        $reg->delete();

        return response(["status" => "Removido com sucesso"], 200);
    }
}

{'fraction_non_alphanumeric': 0.16030534351145037, 'fraction_numerical': 0.0061795710650672485, 'mean_word_length': 1.9475093733261917, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3301399', 'n_tokens_mistral': 1737, 'n_tokens_neox': 1712, 'n_words': 347}