Guest User

Untitled

a guest
Oct 23rd, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.16 KB | None | 0 0
  1. <link href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css" rel="stylesheet">
  2. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"></script>
  3. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
  4. <script src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script>
  5.  
  6. @extends('layouts.app')
  7.  
  8. @section('content')
  9.  
  10. <div class="container">
  11. <div class="row justify-content-center">
  12. <div class="col-md-8">
  13. <div class="card">
  14. <div class="card-header">Dashboard</div>
  15.  
  16. <div class="card-body">
  17. @if (session('status'))
  18. <div class="alert alert-success" role="alert">
  19. {{ session('status') }}
  20. </div>
  21. @endif
  22.  
  23. Has iniciado sesion
  24. </div>
  25. </div>
  26. </div>
  27. </div>
  28. </div>
  29. <br></br>
  30. <center><div class="w3-container">
  31.  
  32. <div class="w3-bar w3-black">
  33. <button class="w3-bar-item w3-button tablink w3-red"
  34. onclick="opentab(event,'London')">Meter datos</button>
  35. <button class="w3-bar-item w3-button tablink"
  36. onclick="opentab(event,'Paris')">Ver datos</button>
  37. </div></center>
  38.  
  39. <div id="London" class="w3-container w3-border city">
  40. <div class="row">
  41.  
  42. <div class="col-md-12">
  43. <br />
  44. <center><h3>Meter datos del producto</h3></center>
  45. <br />
  46. <form method="post" action="{{url('home/sendData')}}">
  47. {{csrf_field()}}
  48. <div class="form-group" align="center">
  49. <input type="text" name="nombre" class="form-control" placeholder="Coloque el nombre del producto" />
  50. </div>
  51. <div class="form-group" align="center">
  52. <input type="number" name="precio" class="form-control" placeholder="Coloque el precio" />
  53. </div>
  54. <div class="form-group" align="center">
  55. <input type="text" name="empresa" class="form-control" placeholder="Coloque el nombre de la empresa" />
  56. </div>
  57. <div class="form-group" align="center">
  58. <input type="submit" class="btn btn-primary" />
  59. </div>
  60.  
  61. </form>
  62.  
  63. </div>
  64. </div>
  65.  
  66. </div>
  67.  
  68. <div id="Paris" class="w3-container w3-border city" style="display:none">
  69. <h2>Productos actuales </h2>
  70. <table class="table table-bordered" id="table">
  71. <thead>
  72. <tr>
  73. <th>Id</th>
  74. <th>Nombre</th>
  75. <th>Precio</th>
  76. <th>Empresa</th>
  77. </tr>
  78. </thead>
  79. </table>
  80. </div>
  81. <script>
  82. $(function() {
  83. $('#table').DataTable({
  84. processing: true,
  85. serverSide: true,
  86. ajax: '{{ url('home') }}',
  87. columns: [
  88. { data: 'id', name: 'id' },
  89. { data: 'nombre', name: 'nombre' },
  90. { data: 'precio', name: 'precio' }
  91. { data: 'empresa', name: 'empresa' }
  92. ]
  93. });
  94. });
  95. </script>
  96.  
  97. <script>
  98. function opentab(evt, cityName) {
  99. var i, x, tablinks;
  100. x = document.getElementsByClassName("city");
  101. for (i = 0; i < x.length; i++) {
  102. x[i].style.display = "none";
  103. }
  104. tablinks = document.getElementsByClassName("tablink");
  105. for (i = 0; i < x.length; i++) {
  106. tablinks[i].className = tablinks[i].className.replace(" w3-red", "");
  107. }
  108. document.getElementById(cityName).style.display = "block";
  109. evt.currentTarget.className += " w3-red";
  110. }
  111. </script>
  112.  
  113.  
  114. @endsection
  115.  
  116. <?php
  117.  
  118. namespace AppHttpControllers;
  119. use AppProduct;
  120. use IlluminateHttpRequest;
  121. use IlluminateSupportFacadesDB;
  122. use YajraDataTablesFacadesDataTables;
  123.  
  124. class HomeController extends Controller
  125. {
  126. /**
  127. * Create a new controller instance.
  128. *
  129. * @return void
  130. */
  131. public function __construct()
  132. {
  133. $this->middleware('auth');
  134. }
  135.  
  136. /**
  137. * Show the application dashboard.
  138. *
  139. * @return IlluminateHttpResponse
  140. */
  141. public function index()
  142. {
  143. return view('home');
  144. return Datatables::of(Product::query())->make(true);
  145. }
  146.  
  147. public function sendData(Request $request){
  148. $this->validate($request, [
  149. 'nombre' => 'required',
  150. 'precio' => 'required',
  151. 'empresa' => 'required'
  152. ]);
  153.  
  154. $product = new product([
  155. 'nombre' => $request->get('nombre'),
  156. 'precio' => $request->get('precio'),
  157. 'empresa' => $request->get('empresa')
  158. ]);
  159. $product->save();
  160. return redirect()->route('home')->with('success', 'Data Added');
  161. }
  162.  
  163. public function create()
  164. {
  165. return view('home');
  166. }
  167.  
  168.  
  169. }
  170.  
  171. Route::get('/', function () {
  172. return view('welcome');
  173. });
  174.  
  175.  
  176. Auth::routes();
  177.  
  178. Route::get('/home', 'HomeController@index')->name('home');
  179. Route::post('/home/sendData', 'HomeController@sendData')->name('home/sendData');
  180.  
  181. Route::get('/home/create', 'HomeController@create');
  182. Route::get('/home/index', 'HomeController@index');
  183.  
  184. <?php
  185.  
  186. namespace App;
  187.  
  188. use IlluminateDatabaseEloquentModel;
  189.  
  190. class Product extends Model
  191. {
  192. protected $fillable = ['nombre', 'precio', 'empresa'];
  193. }
  194.  
  195. CREATE TABLE `products` (
  196. `id` int(10) UNSIGNED NOT NULL,
  197. `producto` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
  198. `precio` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
  199. `empresa` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
  200. `created_at` timestamp NULL DEFAULT NULL,
  201. `updated_at` timestamp NULL DEFAULT NULL) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
Add Comment
Please, Sign In to add comment