Está en la página 1de 16

TECNOLOGÍA WEB II – ULADECH MGTR.

JENNIFER DENISSE SULLÓN CHINGA

I. PROYECTO EN LARAVEL

 CREAMOS UN PROYECTO EN LARAVEL

Ingresamos al terminal y revisamos que nos encontremos dentro de la carpeta www.

cd.. Para salir de una carpeta

cd Nombredelacarpeta Para ingresar a una carpeta

 INGRESAMOS A SUBLIME Y OBSERVAMOS NUESTRO PROYECTO


TECNOLOGÍA WEB II – ULADECH MGTR. JENNIFER DENISSE SULLÓN CHINGA

 CREAMOS NUESTRA BASE DE DATOS

Creamos nuestra base de datos llamada bdproyecto


TECNOLOGÍA WEB II – ULADECH MGTR. JENNIFER DENISSE SULLÓN CHINGA

 INGRESAMOS A .env

Aquí agregamos información para poder conectarnos a nuestra base de datos (SOLO
MODIFICAMOS LO QUE SE MUESTRA A CONTINUACIÓN)

No se debe agregar el
comentario en este
código.
TECNOLOGÍA WEB II – ULADECH MGTR. JENNIFER DENISSE SULLÓN CHINGA

 MODIFICAR EL MÉTODO QUE PERMITIRÁ REALIZAR LAS MIGRACIONES

APPSERVICEPROVIDER.PHP
<?php
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Schema;
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* @return void
*/
public function register()
{
//
}
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
Schema::defaultStringLength(191); }
}
TECNOLOGÍA WEB II – ULADECH MGTR. JENNIFER DENISSE SULLÓN CHINGA

 MIGRAR ESTRUCTURAS EXISTENTES


Aquí encontramos algunas
estructuras de tablas creadas por
defecto:
 Create_users_table.php
 Créate_password_resets_table.php
 Créate_failes_jobs_table.php

En el terminal se debe utilizar el siguiente comando para migrar las estructuras


existentes.
php artisan migrate En la base de datos deben ya
observarse todas las tablas menos la
tabla clientes que es la que
crearemos más adelante.

 CREAR MODELO CLIENTES

Se debe crear el modelo, controlador y recursos necesarios para Clientes, se


debe ingresar el siguiente comando en el terminal:
php artisan make:model clientes -mcr

Observamos que se han creado algunos archivos que nos servirán a lo largo del
desarrollo del proyecto:
 Clientes.php (Modelo Clientes)
 ClientesController.php (Controlador de Cliente)
 Create_table_clientes.php (Recursos como esta migración para trabajar
en nuestra Base de datos)
TECNOLOGÍA WEB II – ULADECH MGTR. JENNIFER DENISSE SULLÓN CHINGA
TECNOLOGÍA WEB II – ULADECH MGTR. JENNIFER DENISSE SULLÓN CHINGA

Ingresamos a create_clientes_table.php
createtableclientes.php
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateClientesTable extends Migration


{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('clientes', function (Blueprint $table) {
$table->increments ('id');
$table->String ('nombre');
$table->String ('apellidopaterno'); Aquí agregamos la estructura de la
$table->String ('apellidomaterno'); tabla.
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('clientes');
}
}

En el terminal se debe utilizar el siguiente comando para migrar la tabla cliente.


php artisan migrate
Para cotejarlo actualizar la base de datos y revisar que ya se observe la tabla
cliente.

 CREAR VISTAS
Se deben crear las vistas: index, create, edit, form; todas deben tener la extensión
.blade.php. Estas vistas solo contendrán un simple texto indicando el nombre de la vista.
TECNOLOGÍA WEB II – ULADECH MGTR. JENNIFER DENISSE SULLÓN CHINGA

 CREAR ALGUNAS RUTAS

WEB.PHP
<?php

use Illuminate\Support\Facades\Route;

Route::get('/', function () {
return view('welcome');
});

Route::get('/clientes', function () {
return view('clientes.index');
});

Route::get('/clientes/create', function () {
return view('clientes.create');
});
TECNOLOGÍA WEB II – ULADECH MGTR. JENNIFER DENISSE SULLÓN CHINGA

 ENLAZAMOS LAS RUTAS A NUESTRO CONTROLADOR

CLIENTESCONTROLLER.PHP
<?php

namespace App\Http\Controllers;

use App\Models\Clientes;
use Illuminate\Http\Request;

class ClientesController extends Controller


{
public function index()
{
return view('clientes.index');
}

public function create()


{
return view('clientes.create');
}

public function store(Request $request)


{
//
}

public function show(Clientes $clientes)


{
//
}

public function edit(Clientes $clientes)


{
//
}

public function update(Request $request, Clientes $clientes)


{
//
}

public function destroy(Clientes $clientes)


{
//
}
}
TECNOLOGÍA WEB II – ULADECH MGTR. JENNIFER DENISSE SULLÓN CHINGA

 EN LAS RUTAS LLAMAMOS AL RESPECTIVO CONTROLADOR

WEB.PHP
<?php

use Illuminate\Support\Facades\Route;

Route::get('/', function () {
return view('welcome');
});
Route::get('/clientes', 'App\Http\Controllers\ClientesController@index');
Route::get('/clientes/create', 'App\Http\Controllers\ClientesController@create');

Nota: Lo subrayado pertenece al namespace del controlador (ruta), no debería ser


necesario agregarlo solo se debería agregar en el caso de que el controlador no se
encuentre a pesar de que se ha creado correctamente.

 VISUALIZAR LA LISTA DE RUTAS EN EL TERMINAL

 PARA CREAR TODAS LAS RUTAS NECESARIAS PARA NUESTRO PROYECTO

WEB.PHP
<?php

use Illuminate\Support\Facades\Route;

Route::get('/', function () {

return view('welcome');

});

Route::resource('clientes','App\Http\Controllers\ClientesController');
TECNOLOGÍA WEB II – ULADECH MGTR. JENNIFER DENISSE SULLÓN CHINGA

En el terminal verificamos todas las rutas que se han creado con su respectivo nombre
y controlador.

 IMPLEMENTAR TODOS LOS MÉTODOS DEL CONTROLADOR PARA LLAMAR A LA VISTA


CORRESPONDIENTE

CLIENTESCONTROLLER.PHP
<?php

namespace App\Http\Controllers;

use App\Models\Clientes;
use Illuminate\Http\Request;

class ClientesController extends Controller


{
public function index()
{ return view('clientes.index'); }

public function create()


{ return view('clientes.create'); }

public function store(Request $request)


{ return view('clientes.store'); }

public function show(Clientes $clientes)


{ return view('clientes.show'); }

public function edit(Clientes $clientes)


{ return view('clientes.edit'); }

public function update(Request $request, Clientes $clientes)


{ return view('clientes.update'); }

public function destroy(Clientes $clientes)


{ return view('clientes.destroy'); }
TECNOLOGÍA WEB II – ULADECH MGTR. JENNIFER DENISSE SULLÓN CHINGA

 INGRESAR A UNA RUTA DESDE EL NAVEGADOR

 localhost/proyecto/public/cliente
 localhost/proyecto/public/cliente/create
 localhost/proyecto/public/cliente/show
 localhost/proyecto/public/cliente/edit
 localhost/proyecto/public/cliente/update

II. INGRESAR DATOS

 CREAR FORMULARIO PARA CAPTURAR INFORMACIÓN

CREATE.BLADE.PHP
<h2>AGREGAR CLIENTES</h2>

<br>

<form action="{{url('/clientes')}}" method="post" enctype="multipart/form-data">

{{csrf_field()}}

<label for="Nombre">{{'Nombre'}}</label>

<input type="text" name="Nombre" id="Nombre" value="">

<br><br>

<label for="ApellidoPaterno">{{'ApellidoPaterno'}}</label>

<input type="text" name="ApellidoPaterno" id="ApellidoPaterno" value="">

<br><br>

<label for="ApellidoMaterno">{{'ApellidoMaterno'}}</label>

<input type="text" name="ApellidoMaterno" id="ApellidoMaterno" value="">

<br><br>

<input type="submit" value="AGREGAR">

</form>
TECNOLOGÍA WEB II – ULADECH MGTR. JENNIFER DENISSE SULLÓN CHINGA

 MODIFICAMOS EL CONTROLADOR PARA PODER RECIBIR LOS DATOS QUE SERÁN


INGRESADOS POR EL FORMULARIO
Modificar la función STORE

CLIENTESCONTROLLER.PHP
public function store(Request $request)
{
$datosClientes=request()->except('_token');
clientes::insert ($datosClientes);
return response()->json($datosClientes);
}

 INGRESAR DATOS EN EL FORMULARIO


Ingresamos a la ruta correspondiente desde nuestro navegador.

Verificamos que en nuestra tabla se hayan insertado la información.


TECNOLOGÍA WEB II – ULADECH MGTR. JENNIFER DENISSE SULLÓN CHINGA

III. LISTAR DATOS

 MODIFICAMOS EL MÉTODO INDEX DEL CONTROLADOR

CLIENTESCONTROLLER.PHP
public function index()
{
$datos ['clientes']=Clientes::paginate(5);
return view('clientes.index',$datos);
}

 IMPLEMENTAMOS INDEX
Para mostrar toda la información que he recuperado de Clientes

INDEX.BLADE.PHP
INICIO

<table class="table table-light">

<!--Nombre de las columnas-->


<thead class="thead-light">
<tr>
<th>#</th>
<th>Nombre</th>
<th>Apellido Paterno</th>
<th>Apellido Materno</th>
<th>Acciones</th>
</tr>
</thead>

<!--Contenido de cada uno de los registros-->


<tbody>
@foreach ($clientes as $clientes)
<tr>
<td>{{$loop->iteration}}</td>
<td>{{$clientes->nombre}}</td>
<td>{{$clientes->apellidopaterno}}</td>
<td>{{$clientes->apellidomaterno}}</td>
<td>Editar|Borrar</td>
</tr>
@endforeach
</tbody>

</table>
TECNOLOGÍA WEB II – ULADECH MGTR. JENNIFER DENISSE SULLÓN CHINGA

IV. ELIMINAR DATOS


 IMPLEMENTAMOS EL BOTÓN ELIMINAR

INDEX.BLADE.PHP
<H1> LISTAR DATOS </H1>
<table class="table table-light">
<!--Nombre de las columnas-->
<thead class="thead-light">
<tr>
<th>#</th>
<th>Nombre</th>
<th>Apellido Paterno</th>
<th>Apellido Materno</th>
<th>Acciones</th>
</tr>
</thead>

<!--Contenido de cada uno de los registros-->


<tbody>
@foreach ($clientes as $clientes)
<tr>
<td>{{$loop->iteration}}</td>
<td>{{$clientes->nombre}}</td>
<td>{{$clientes->apellidopaterno}}</td>
<td>{{$clientes->apellidomaterno}}</td>
<td>Editar|
<form method="post" action="{{url('/clientes/'.$clientes->id)}}">
{{csrf_field()}}
{{method_field('DELETE')}}
<button type="submit" onclick="return confirm('¿Eliminar?');">Eliiminar</button>
</form>
TECNOLOGÍA WEB II – ULADECH MGTR. JENNIFER DENISSE SULLÓN CHINGA

</td>
</tr>
@endforeach
</tbody>

</table>

 MODIFICAMOS EL MÉTODO DESTROY DEL CONTROLADOR

CLIENTESCONTROLLER.PHP

public function destroy($id)


{
clientes::destroy($id);
return redirect('clientes');
}

EJERCICIO:
1.- Crear un proyecto en laravel done se pueda visualizar una lista de Proveedores,
agregar y eliminar los mismos.
Se desea conocer del Proveedor: Código, Nombre, Domicilio, Ciudad, Teléfono.

También podría gustarte