Created
May 16, 2019 01:42
-
-
Save carlos-silveira/34592ec67f8b82de36e5fccde0b2a8ab to your computer and use it in GitHub Desktop.
Forms, modal and update Lavarel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@extends('dash.layouts.main') | |
@section('content') | |
<h1>Bienvenido a Productos</h1> | |
@if($errors->any()) | |
<div class="col-12 alert alert-danger alert-dismissible fade show" role="alert"> | |
<h5>Error:</h5> | |
<ul> | |
@foreach($errors->all() as $error) | |
<li>{{$error}}</li> | |
@endforeach | |
</ul> | |
<button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
<span aria-hidden="true">×</span> | |
</button> | |
</div> | |
@endif | |
@if( $message=Session::get('Listo') ) | |
<div class="col-12 alert alert-success alert-dismissible fade show" role="alert"> | |
<h5>Listo:</h5> | |
<span>{{$message}}</span> | |
<button type="button" class="close" data-dismiss="alert" aria-label="Close"> | |
<span aria-hidden="true">×</span> | |
</button> | |
</div> | |
@endif | |
<div class="row container"> | |
<div class="col-8"> | |
<h2>Lista de productos</h2> | |
<table class="table"> | |
<thead> | |
<tr> | |
<td>Imagen</td> | |
<td>ID</td> | |
<td>Codigo</td> | |
<td>Nombre</td> | |
<td>Precio</td> | |
<td>Stock</td> | |
<td></td> | |
</tr> | |
</thead> | |
<tbody> | |
@foreach($Productos as $p) | |
<tr> | |
<td><img src="{{asset('img/productos/'.$p->img)}}" width="25px"></td> | |
<td>{{$p->id}}</td> | |
<td>{{$p->codigo}}</td> | |
<td>{{$p->name}}</td> | |
<td>{{$p->precio}}</td> | |
<td>{{$p->stock}}</td> | |
<td> | |
<button type="button" class="btn btn-outline-primary btn-sm btnEditar" | |
data-toggle="modal" data-target="#exampleModalLong" | |
data-name="{{$p->name}}" | |
data-id="{{$p->id}}" | |
data-codigo="{{$p->codigo}}" | |
data-precio="{{$p->precio}}" | |
data-stock="{{$p->stock}}" | |
> | |
<i class="fas fa-edit"></i> | |
</button> | |
<form action="{{url('/admin/productos',['id'=>$p->id])}}" method="post"> | |
@csrf | |
<input type="hidden" name="id" value="{{$p->id}}"> | |
<input type="hidden" name="_method" value="delete"> | |
<button type="submit" class="btn btn-outline-danger btn-sm"> | |
<i class="fas fa-trash"></i> | |
</button> | |
</form> | |
</td> | |
</tr> | |
@endforeach | |
</tbody> | |
</table> | |
</div> | |
<div class="col-4"> | |
<h2>Agregar productos</h2> | |
<form enctype="multipart/form-data" method="post" action="/admin/productos"> | |
@csrf | |
<div class="form-group"> | |
<label for="">Nombre</label> | |
<input required type="text" class="form-control" placeholder="Nombre" name="name" value=""> | |
</div> | |
<div class="form-group"> | |
<label for="">Codigo</label> | |
<input required type="text" class="form-control" placeholder="Codigo" name="codigo" value=""> | |
</div> | |
<div class="form-group"> | |
<label for="">Imagen</label> | |
<input required type="file" name="imagen" value=""> | |
</div> | |
<div class="form-group"> | |
<label for="">Precio</label> | |
<input required type="text" class="form-control" placeholder="Precio" name="precio" value=""> | |
</div> | |
<div class="form-group"> | |
<label for="">Stock</label> | |
<input max="100" min="1" required class="form-control" type="number" placeholder="Stock" name="stock" value=""> | |
</div> | |
<div class="form-group"> | |
<button type="submit" class="btn btn-primary">Ingresar</button> | |
<input type="reset" value="reset" class="btn btn-warning"> | |
</div> | |
</form> | |
</div> | |
</div> | |
<div class="modal fade" id="exampleModalLong" tabindex="-1" role="dialog" aria-labelledby="exampleModalLongTitle" aria-hidden="true"> | |
<div class="modal-dialog" role="document"> | |
<div class="modal-content"> | |
{{ Form::open(array('url' => '/admin/productos/update')) }} | |
<div class="modal-header"> | |
<h5 class="modal-title" id="exampleModalLongTitle"> | |
Editar: <b id="titleEditar"></b> | |
</h5> | |
<button type="button" class="close" data-dismiss="modal" aria-label="Close"> | |
<span aria-hidden="true">×</span> | |
</button> | |
</div> | |
<div class="modal-body"> | |
{{Form::hidden('id','',['id'=>'idEditar'])}} | |
<div class="form-group"> | |
<label>Codigo</label> | |
{{ Form::text('codigo','',['class'=>'form-control','id'=>'codigoEdit']) }} | |
</div> | |
<div class="form-group"> | |
<label>Nombre</label> | |
{{ Form::text('name','',['class'=>'form-control','id'=>'nameEdit']) }} | |
</div> | |
<div class="form-group"> | |
<label>Precio</label> | |
{{ Form::text('precio','',['class'=>'form-control','id'=>'precioEdit']) }} | |
</div> | |
<div class="form-group"> | |
<label>Stock</label> | |
{{ Form::text('stock','',['class'=>'form-control','id'=>'stockEdit']) }} | |
</div> | |
</div> | |
<div class="modal-footer"> | |
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> | |
<button type="submit" class="btn btn-primary">Actualizar</button> | |
</div> | |
{{Form::close() }} | |
</div> | |
</div> | |
</div> | |
@endsection | |
@section('scripts') | |
<script> | |
$(document).ready(function(){ | |
$(".btnEditar").on('click',function(){ | |
$("#titleEditar").text($(this).data('name')); | |
var codigo=$(this).data('codigo'); | |
$("#codigoEdit").val(codigo); | |
$("#nameEdit").val($(this).data('name')); | |
$("#precioEdit").val($(this).data('precio')); | |
$("#stockEdit").val($(this).data('stock')); | |
$("#idEdit").val($(this).data('id')); | |
}); | |
}); | |
</script> | |
@endsection |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment