sergionc

sergionc

Member Since 8 Months Ago

Experience Points
1,200
Total
Experience

3,800 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
0
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 1
1,200 XP
Apr
06
3 days ago
Activity icon

Replied to Delete Record With Fetch Api

It works fine, I usually delete a record like this:

              <form action="{{route('persona.destroy', $persona->id)}}"
                            class="d-inline" method="post">
                            @csrf
                            @method('delete')
                            <button class="btn btn-danger btn-sm btnhola" type="submit">
                                <i class="fas fa-times">
                                </i>
                            </button>
                        </form>

Now I want to do it through fetch api js vanilla.

Activity icon

Started a new Conversation Delete Record With Fetch Api

I am trying to delete a record using fetch api but I get the following error: The GET method is not supported for this route. Supported methods: DELETE.

button:

                        <button class="btn btn-danger btn-sm"
                            onclick="deletePersona({{$persona->id}})">
                            <i class="fas fa-times">
                            </i>
                        </button>

Code js:

function deletePersona(id) { fetch("/persona_eliminar/" + id, { method: "DELETE", }) .then((res) => res.json()) .then((response) => { console.log(response); }); }

Apr
02
1 week ago
Activity icon

Replied to Select Dynamic With Livewire

@Snapey I have followed the example to the letter, but it throws the same error: Unresolvable dependency resolving [Parameter #0 [ $country ]] in class App\Http\Livewire\SelectCiudad...

Activity icon

Started a new Conversation Select Dynamic With Livewire

Hello friends, I am trying to do dynamic select using livewire, any help?

Component:

public $ciudades=[];

public function render()
{
    $regiones = Region::all();
    return view('livewire.select-ciudad',compact('regiones'));
}

public function showciudades($id)
{
    $this->ciudades = Ciudad::where('region_id', '=',$id)->get();
}

View, select father :

    <select class="form-control" style="width: 100%">
        @foreach ($regiones as $region)
            <option value="{{ $region->id }}" wire:click="showciudades({{$region->id}})">
                {{ $region->nombre_region }}
            </option>
        @endforeach
    </select>

Select son:

    <select name="ciudad_id" class="form-control" style="width: 100%">
        @foreach($ciudades as $ciudad)
        <option value="{{$ciudad->id}}">{{$ciudad->nombre_ciudad}}</option>
        @endforeach
    </select>
Mar
12
4 weeks ago
Activity icon

Replied to Optimize Query Line

excellent, thanks for the clarification.

Activity icon

Replied to Optimize Query Line

@jlrdw I would like to use something like this: Alumno::create();

Activity icon

Started a new Conversation Optimize Query Line

I currently save with this method:

    $alumno = new Alumno();
    $alumno->user_id = auth()->id();
    $alumno->nombres = $request->nombres;
    $alumno->apellidos = $request->apellidos;
    $alumno->nacionalidad = $request->nacionalidad;
    $alumno->ciudad_id = $request->ciudad_id;
    $alumno->edad = $request->edad;
    $alumno->grado = $request-grado
    $alumno->seccion = $request->seccion;
    $alumno->save();
    return redirect('lista_alumnos')->with('success', 'Registrado con éxito!');

how could I use Alumno:: create (); Knowing that I have the field $alumno->user_id = auth()->id();

Activity icon

Started a new Conversation Default Role For New Users

Applying the spatie permission package, to each new registered user that has a default role.

Default function of creating users:

protected function create(array $data)

{ return User::create([ 'name' => $data['name'], 'email' => $data['email'], 'password' => Hash::make($data['password']), 'nacimiento' => $data['nacimiento'], 'sexo' => $data['sexo'] ]); }

I tried something like:

$user = User::latest('id')->first();

$user->hasRole('visita');

Mar
07
1 month ago
Activity icon

Replied to Eloquent Does Not Relate Model

@tisuchi SQLSTATE[42S22]: Column not found: 1054 Unknown column 'regions.ciudad_id' in 'where clause' (SQL: select * from regions where regions.ciudad_id in (1, 2, 3, 4, 5, 6, 7))

All tables your ID are by convection, because it will be the error

Activity icon

Replied to Eloquent Does Not Relate Model

@tisuchi It doesn't let me access the relationship, it seems that something is wrong; Message: Property [region] does not exist on this collection instance.

Activity icon

Started a new Conversation Eloquent Does Not Relate Model

Model Region

class Region extends Model { protected $fillable = [

    'nombre_region'
];

public function ciudad()
{
    return $this->belongsTo(Ciudad::class);
}

}

Model Ciudad

class Ciudad extends Model { protected $fillable = [

    'region_id','nombre_ciudad'
];

public function regions()
{
    return $this->hasMany(Region::class);
}

}

$ciudadeslista = Ciudad::all();

dd($ciudadeslista->regions->nombre_region);

Property [region] does not exist on this collection instance.

Dec
04
4 months ago
Activity icon

Replied to Validate Form Submissions

The problem is not the validation in the form fields, but in the controller. My fields are validated according to type. The problem is that if I quickly click several click on my register button, it sends multiple data.

Activity icon

Started a new Conversation Validate Form Submissions

Any idea how to validate the submission of data from a form. When multiple clicks are made on the button, record the information in several rows. The server side validation.

$(document).ready(function() {
    $(':submit').click(function() {
        $(':submit').attr('disabled', true);
        $('.formulario').submit();
        return true;
    });
});

I use it with jquery on the client side, but I need an idea to validate on the other side. Thank you

Dec
02
4 months ago
Activity icon

Replied to Update Array

something like that? I can only update the "Prestamo" model, I do not achieve in "Presocio"

public function update(PrestamoRequest $request, $id) { $prestamo = Prestamo::findOrFail($id); $prestamo->socio_id = $request->socio_id; $prestamo->monto = $request->monto; $prestamo->cuotas = $request->cuotas; $prestamo->alias = $request->alias; $prestamo->estado = $request->estado; $prestamo->update(); $idprestamo = $prestamo->id;

    if (count($request->ncuota) > 0) {
        foreach ($request->ncuota as $item => $v) {
            $presocio = Presocio::findOrFail($id);
            $presocio->fill(
                array(
                    'prestamo_id' => $idprestamo,
                    'ncuota'      => $request->ncuota[$item],
                    'montopag'    => $request->montopag[$item],
                    'fechapag'    => $request->fechapag[$item],
                    'estadopag'   => $request->estadopag[$item],
                )
            );
            $presocio->update();
        }
    }
    toast('Pago Programados Editado', 'success');
    return redirect('prestamo');
}
Activity icon

Started a new Conversation Update Array

How would my function to update.

public function store(PrestamoRequest $request)
{
    $prestamo           = new Prestamo;
    $prestamo->socio_id = $request->socio_id;
    $prestamo->monto    = $request->monto;
    $prestamo->cuotas   = $request->cuotas;
    $prestamo->alias    = $request->alias;
    $prestamo->estado   = $request->estado;
    $prestamo->save();
    $idprestamo = $prestamo->id;

    if (count($request->ncuota) > 0) {
        foreach ($request->ncuota as $item => $v) {
            $presocio = new Presocio;
            $presocio->fill(
                array(
                    'prestamo_id' => $idprestamo,
                    'ncuota'      => $request->ncuota[$item],
                    'montopag'    => $request->montopag[$item],
                    'fechapag'    => $request->fechapag[$item],
                    'estadopag'   => $request->estadopag[$item],
                )
            );
            $presocio->save();
        }
    }
    toast('Pago Programados Registrado', 'success');
    return redirect('prestamo');
}

This is my function to save, how to modify to update, thanks

Dec
01
4 months ago
Activity icon

Replied to Change Save To Create

If it was already corrected. Thank you

Nov
30
4 months ago
Activity icon

Replied to Change Save To Create

In the end it works like this:

    $prestamo           = new Prestamo;
    $prestamo->socio_id = $request->socio_id;
    $prestamo->monto    = $request->monto;
    $prestamo->cuotas   = $request->cuotas;
    $prestamo->alias    = $request->alias;
    $prestamo->estado   = $request->estado;
    $prestamo->save();
    $idprestamo = $prestamo->id;

    if (count($request->ncuota) > 0) {
        foreach ($request->ncuota as $item => $v) {
            $presocio = new Presocio;
            $presocio->fill(
                array(
                    'prestamo_id' => $idprestamo,
                    'ncuota'      => $request->ncuota[$item],
                    'montopag'    => $request->montopag[$item],
                    'fechapag'    => $request->fechapag[$item],
                )
            );
            $presocio->save();
        }
    }
    toast('Pago Programados Registrado', 'success');
    return redirect('prestamo');
Activity icon

Replied to Change Save To Create

Undefined variable: prestamo_id

Activity icon

Replied to Change Save To Create

Correct, sorry for the inconvenience. The opposite can be done here, change the :: create to the -> save

public function store(PrestamoRequest $request)
{
    $data        = $request->all();
    $prestamo_id = Prestamo::create($data)->id;
    if (count($request->ncuota) > 0) {
        foreach ($request->ncuota as $item => $v) {
            $data2 = array(
                'prestamo_id' => $prestamo_id,
                'ncuota'      => $request->ncuota[$item],
                'montopag'    => $request->montopag[$item],
                'fechapag'    => $request->fechapag[$item],
                'estado'      => $request->estado[$item],
            );
            Presocio::create($data2);
        }
    }
    toast('Pago Programados Registrado', 'success');
    return redirect('prestamo');

}
Activity icon

Replied to Change Save To Create

"isDirty" to notify if I make a change in the form, otherwise do not make any changes and click on the "edit" button would show a success message, when in fact you did not make any changes.

rather to detect if data is actually being updated and do not send them.

Activity icon

Replied to Change Save To Create

and where the "isDirty"

Activity icon

Started a new Conversation Change Save To Create

how could I change the code so that it is with "CREATE" instead of -> save with condition isDirty

public function update(AhorrogaRequest $request, $id)
{
    $ahorroga           = Ahorroga::findOrFail($id);
    $ahorroga->junta_id = $request->junta_id;
    $ahorroga->socio_id = $request->socio_id;
    $ahorroga->ahorro   = $request->ahorro;
    $ahorroga->estado   = $request->estado;

    if ($ahorroga->isDirty()) {
        $ahorroga->save();
        toast('Ahorro Garantia Editado', 'success');
        return redirect('ahorroga');
    }
    toast('No se detectaron cambios', 'error');
    return redirect('ahorroga');
}
Nov
26
4 months ago
Activity icon

Replied to Insert Multiple Data Laravel

I have an idea, with Jquery adding rows to an html table and in this way I can have more fields to fill.

My question is how the "name" of each input would be to be received in the controller.

This is my form to send data.

    {{-- OPEN FORM --}}
    {!! Form::open(['route'=>'presocio.store', 'method'=>'POST']) !!}
    <button class="btn btn-info" id="addrow" type="button">
        +
    </button>
    <div class="row">
        <div class="col-md-3 col-12">
            <div class="form-group">
                {!! Form::label(null,'Seleccionar Prestamo:',
                ['class'=>'text-dark font-weight-bold']) !!}
                {!! Form::select('prestamo_id', $prestamos, null,
                ['id'=>'selectsocio','class' =>'form-control']) !!}
                <p class="text-danger">
                    {{ $errors->first('prestamo_id') }}
                </p>
            </div>
        </div>
        <div class="col-md-3 col-12">
            <div class="form-group">
                {!! Form::label(null,'Cuota a Pagar:',
                ['class'=>'text-dark font-weight-bold']) !!}
                {!! Form::number('ncuota', null,
                ['class'=> 'form-control','placeholder'=>'Cuota a Pagar','required' => 'required']) !!}
                <p class="text-danger">
                    {{ $errors->first('ncuota') }}
                </p>
            </div>
        </div>
        <div class="col-md-3 col-12">
            <div class="form-group">
                {!! Form::label(null,'Monto a Pagar:',
                ['class'=>'text-dark font-weight-bold']) !!}
                {!! Form::number('montopag', null,
                ['class'=> 'form-control','placeholder'=>'Monto a Pagar','required' => 'required']) !!}
                <p class="text-danger">
                    {{ $errors->first('montopag') }}
                </p>
            </div>
        </div>
        <div class="col-md-3 col-12">
            <div class="form-group">
                {!! Form::label(null,'Fecha a Pagar:',
                ['class'=>'text-dark font-weight-bold']) !!}
                {!! Form::text('fechapag', null,
                ['class'=> 'form-control','placeholder'=>'Fecha a Pagar','required' => 'required']) !!}
                <p class="text-danger">
                    {{ $errors->first('fechapag') }}
                </p>
            </div>
        </div>
        <div class="col-12">
            <div class="form-group">
                <button class="btn btn-success btn-sm" type="submit">
                    <i class="fas fa-check">
                    </i>
                    Registrar
                </button>
                <a class="btn btn-danger btn-sm" href="{{ route('presocio.index') }}">
                    <i class="fas fa-times">
                    </i>
                    Cancelar
                </a>
            </div>
        </div>
    </div>
    {{-- CLOSE FORM --}}
    {!! Form::Close() !!}

public function store(Request $request) { $request->validate([ 'prestamo_id' => 'required|numeric', 'ncuota' => 'required|numeric', 'montopag' => 'required|numeric', 'fechapag' => 'required|date', ]);

    $presocio              = new Presocio;
    $presocio->prestamo_id = $request->prestamo_id;
    $presocio->ncuota      = $request->ncuota;
    $presocio->montopag    = $request->montopag;
    $presocio->fechapag    = $request->fechapag;
    $presocio->save();

    toast('Pago Programados Registrado', 'success');
    return redirect('presocio');
}
Nov
22
4 months ago
Activity icon

Replied to Insert Multiple Data Laravel

returns the last row inserted from the view, the previous rows does not recognize.

Activity icon

Replied to Insert Multiple Data Laravel

Just register one row, I am sending several rows from the view.

Activity icon

Started a new Conversation Insert Multiple Data Laravel

I am trying to enter several records in a row but only one registers me, would the correct way be? is for a master table, detail.

public function store(Request $request)
{
    $request->validate([
        'prestamo_id' => 'required|numeric',
        'montopag' => 'required|numeric',
        'fechapag' => 'required|date',
    ]);

    $presocio = new Presocio;
    $data = [
        [$presocio->prestamo_id = $request->prestamo_id,
            $presocio->montopag = $request->montopag,
            $presocio->fechapag = $request->fechapag],
    ];
    Presocio::insert($data);

    toast('Pago Programados Registrado','success');
    return redirect('presocio');
}
Nov
20
4 months ago
Activity icon

Started a new Conversation Idea To Calculate With Conditional

Can you give me the idea, I have two fields in my table.

field_1 (always has a value of 5)

field_2 (depends on the days of delay is multiplied by the value of field_1)

My idea would be to use carbon to get the current date and subtract it from the date it was created and in that way multiply by the value of field_1.

But how to do it in a controller since they are for all rows that have a value of 5 in field_1

public function show($id)
{
    $pago = Pago::with('junta','socio')->findOrFail($id);
    $fecha = Carbon::now();
    $freg = $pago->created_at->diffInDays();
    $cpago = $pago->multa;
    $cmulta = $freg*$cpago;
    return view('pago.show', compact('pago','fecha','cmulta'));
}

so get by id, but if I want for all rows and it is done automatically.

Nov
18
4 months ago
Activity icon

Replied to Detect Changes Before Updating

Thank you very much for your solutions.

Activity icon

Started a new Conversation Detect Changes Before Updating

I want to detect changes before updating the data. I have read that isDirty can be used, but I cannot understand how to apply it.

public function update(Request $request, $id)
{
    $request->validate([
        'junta_id' => 'required|numeric',
        'socio_id' => 'required|numeric',
        'ahorro' => 'required|numeric',
        'estado' => 'required|numeric',
    ]);

    Ahorroga::findOrFail($id)->update($request->all());
    toast('Ahorro Garantia Editado','success');
    return redirect('ahorroga');
}
Nov
05
5 months ago
Activity icon

Replied to Datatable Eloquent

great, that needed. Sorry I understand little of datatable. Thanks again.

Activity icon

Replied to Datatable Eloquent

rather, how can I do this, but with datatable eloquent.

    $pagos = Pago::with('junta','socio')->get();
    return $pagos;


    return datatables()
->eloquent(Pago::query())
->addColumn('btn','pago.action')
->rawColumns(['btn'])
->toJson();
Nov
04
5 months ago
Activity icon

Replied to Datatable Eloquent

show a related table via datatable, but if the expected json returns. But I want to show an example in the field of one of the related tables.

$('#table-pago').DataTable( {
    serverSide: true,
    ajax: "{{route('jsonPago')}}",
    columns: [
    {data: 'junta_id'},
    {data: 'socio_id'},
    {data: 'montototal'},
    {data: 'montopagar'},
    {data: 'montorestante'},
    {data: 'multa'},
    {data: 'btn'}
    ]
} );

How would you show: the name of junta_id

Activity icon

Started a new Conversation Datatable Eloquent

correctly returns the json, but if I need a specific column of a related id. Thanks.

public function dtpago()
{
    return datatables()
    ->eloquent(Pago::query())
    ->addColumn('btn','pago.action')
    ->rawColumns(['btn'])
    ->toJson();
}
Nov
03
5 months ago
Activity icon

Replied to Insert Image With Eloquent

the correct thing would be that to update, eliminate the image to be replaced. By topic of space.

Activity icon

Replied to Insert Image With Eloquent

It works fine, excuse me and if I want to update the image

Activity icon

Replied to Insert Image With Eloquent

applied, the image is sent to the folder, but the path in temp is registered in the database. How do I get the route in image form?

Nov
02
5 months ago
Activity icon

Started a new Conversation Insert Image With Eloquent

save the route in temp.

public function store(Request $request)
{

    if($request->hasFile('avatar')){
        $file = $request->file('avatar');
        $name = time().$file->getClientOriginalName();
        $file->move(public_path().'/images/',$name);   
    }

    Foto::create($request->all());   
    return redirect('foto.index');    
    
}
Oct
31
5 months ago
Activity icon

Replied to Update With Eloquent

Sorry, I already found my mistake, Thank you

Activity icon

Started a new Conversation Update With Eloquent

I am trying to edit my form but it does not throw me any error, it just reloads the view

public function update(PagoUpdateRequest $request, $id) { Pago::findOrFail($id)->update($request->all()); Alert::success('Pago Editado', ''); return redirect('pago'); }

class Pago extends Model { protected $fillable = [

    'junta_id',
    'socio_id',
    'ncuota',
    'montototal',
    'montopagar',
    'montorestante',
    'multa',
    'observacion'

];

public function junta(){

    return $this->belongsTo(Junta::class);

}

public function socio(){

    return $this->belongsTo(Socio::class);

}

}