9 changed files with 238 additions and 2 deletions
@ -0,0 +1,73 @@ |
|||
<?php |
|||
|
|||
namespace App\Http\Controllers; |
|||
|
|||
use App\Models\Marca; |
|||
use Illuminate\Http\Request; |
|||
|
|||
class MarcaController extends Controller |
|||
{ |
|||
/** |
|||
* Display a listing of the resource. |
|||
*/ |
|||
public function index() |
|||
{ |
|||
$marcas = Marca::all(); |
|||
return view('marcas', ["marcas" => $marcas]); |
|||
} |
|||
|
|||
/** |
|||
* Show the form for creating a new resource. |
|||
*/ |
|||
public function create() |
|||
{ |
|||
$marcas = Marca::all(); |
|||
return view('marcasCrearEditar',['marcas'=>$marcas]); |
|||
} |
|||
|
|||
/** |
|||
* Store a newly created resource in storage. |
|||
*/ |
|||
public function store(Request $request) |
|||
{ |
|||
$marca = new Marca($request->all()); |
|||
$marca->save(); |
|||
return redirect()->route('marca.index'); |
|||
} |
|||
|
|||
/** |
|||
* Display the specified resource. |
|||
*/ |
|||
public function show(Marca $marca) |
|||
{ |
|||
// |
|||
} |
|||
|
|||
/** |
|||
* Show the form for editing the specified resource. |
|||
*/ |
|||
public function edit($id) |
|||
{ |
|||
$marca = Marca::find($id); |
|||
return view('marcasCrearEditar',['marca'=>$marca]); |
|||
} |
|||
|
|||
/** |
|||
* Update the specified resource in storage. |
|||
*/ |
|||
public function update(Request $request, $id) |
|||
{ |
|||
$marca = Marca::find($id); |
|||
$marca->fill($request->all()); |
|||
$marca->save(); |
|||
return redirect()->route('marca.index'); |
|||
} |
|||
|
|||
/** |
|||
* Remove the specified resource from storage. |
|||
*/ |
|||
public function destroy(Marca $marca) |
|||
{ |
|||
// |
|||
} |
|||
} |
@ -0,0 +1,15 @@ |
|||
<?php |
|||
|
|||
namespace App\Models; |
|||
|
|||
use Illuminate\Database\Eloquent\Factories\HasFactory; |
|||
use Illuminate\Database\Eloquent\Model; |
|||
|
|||
class Marca extends Model |
|||
{ |
|||
use HasFactory; |
|||
|
|||
protected $table = 'marcas'; |
|||
|
|||
protected $fillable = ['nombre']; |
|||
} |
@ -0,0 +1,23 @@ |
|||
<?php |
|||
|
|||
namespace Database\Factories; |
|||
|
|||
use Illuminate\Database\Eloquent\Factories\Factory; |
|||
|
|||
/** |
|||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Marca> |
|||
*/ |
|||
class MarcaFactory extends Factory |
|||
{ |
|||
/** |
|||
* Define the model's default state. |
|||
* |
|||
* @return array<string, mixed> |
|||
*/ |
|||
public function definition(): array |
|||
{ |
|||
return [ |
|||
// |
|||
]; |
|||
} |
|||
} |
@ -0,0 +1,28 @@ |
|||
<?php |
|||
|
|||
use Illuminate\Database\Migrations\Migration; |
|||
use Illuminate\Database\Schema\Blueprint; |
|||
use Illuminate\Support\Facades\Schema; |
|||
|
|||
return new class extends Migration |
|||
{ |
|||
/** |
|||
* Run the migrations. |
|||
*/ |
|||
public function up(): void |
|||
{ |
|||
Schema::create('marcas', function (Blueprint $table) { |
|||
$table->id(); |
|||
$table->string('nombre'); |
|||
$table->timestamps(); |
|||
}); |
|||
} |
|||
|
|||
/** |
|||
* Reverse the migrations. |
|||
*/ |
|||
public function down(): void |
|||
{ |
|||
Schema::dropIfExists('marcas'); |
|||
} |
|||
}; |
@ -0,0 +1,17 @@ |
|||
<?php |
|||
|
|||
namespace Database\Seeders; |
|||
|
|||
use Illuminate\Database\Console\Seeds\WithoutModelEvents; |
|||
use Illuminate\Database\Seeder; |
|||
|
|||
class MarcaSeeder extends Seeder |
|||
{ |
|||
/** |
|||
* Run the database seeds. |
|||
*/ |
|||
public function run(): void |
|||
{ |
|||
// |
|||
} |
|||
} |
@ -0,0 +1,46 @@ |
|||
@extends('layouts.dashboard') |
|||
|
|||
@section('content') |
|||
<div class="row"> |
|||
<div class="col-md-12"> |
|||
<a href="{{ route('marca.create') }}" class="btn btn-primary">Agregar Marca</a> |
|||
</div> |
|||
<div class="card"> |
|||
<div class="card-header"> |
|||
<h3 class="card-title">Lista de Marcas</h3> |
|||
</div> |
|||
<div class="card-body"> |
|||
<div class="table-responsive"> |
|||
<table class="table table-bordered table-striped"> |
|||
<thead> |
|||
<tr> |
|||
<th>ID</th> |
|||
<th>Nombre</th> |
|||
<th>Acciones</th> |
|||
</tr> |
|||
</thead> |
|||
<tbody> |
|||
@foreach($marcas as $marca) |
|||
<tr> |
|||
<td>{{ $marca->id }}</td> |
|||
<td>{{ $marca->nombre }}</td> |
|||
<td> |
|||
<a href="{{ route('marca.edit', $marca->id) }}" class="btn btn-primary btn-sm">Editar</a> |
|||
<form action="{{ route('marca.destroy', $marca->id) }}" method="POST" style="display:inline-block;"> |
|||
@csrf |
|||
@method('DELETE') |
|||
<button type="submit" class="btn btn-danger btn-sm">Eliminar</button> |
|||
</form> |
|||
</td> |
|||
</tr> |
|||
@endforeach |
|||
</tbody> |
|||
</table> |
|||
</div> |
|||
</div> |
|||
</div> |
|||
|
|||
</div> |
|||
|
|||
</div> |
|||
@endsection |
@ -0,0 +1,31 @@ |
|||
@extends('layouts.dashboard') |
|||
|
|||
@section('content') |
|||
<div class="row"> |
|||
<div class="col-md-12"> |
|||
@if($marca) |
|||
<h1>Editar Marca</h1> |
|||
@else |
|||
<h1>Crear Marca</h1> |
|||
@endif |
|||
</div> |
|||
<div class="col-md-12"> |
|||
@if($marca) |
|||
<form action="{{ route('marca.update', $marca->id) }}" method="POST"> |
|||
@csrf |
|||
@method('PUT') |
|||
@else |
|||
<form action="{{ route('marca.store') }}" method="POST"> |
|||
@csrf |
|||
@endif |
|||
|
|||
<div class="form-group"> |
|||
<label for="nombre">Nombre</label> |
|||
<input type="text" class="form-control" id="nombre" name="nombre" required value="{{ $marca->nombre }}"> |
|||
</div> |
|||
<button type="submit" class="btn btn-primary">Aceptar</button> |
|||
<a href="{{ route('marca.index') }}" class="btn btn-danger">Cancelar</a> |
|||
</form> |
|||
</div> |
|||
</div> |
|||
@endsection |
Loading…
Reference in new issue