Creando proyecto
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
abstract class Controller
|
||||
{
|
||||
//
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class HomeController extends Controller
|
||||
{
|
||||
public function __invoke() // * Controlador con un unico metodo se usa __invoke
|
||||
{
|
||||
return view('home');
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,65 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Models\Product;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ProductosController extends Controller
|
||||
{
|
||||
public function index(){
|
||||
$products = Product::orderBy('id','desc')->paginate();
|
||||
return view('productos.index', compact('products'));
|
||||
}
|
||||
|
||||
public function create(){
|
||||
return view('productos.create');
|
||||
}
|
||||
|
||||
public function show($id){
|
||||
$producto = Product::find($id);
|
||||
return view('productos.show', compact('producto'));
|
||||
}
|
||||
|
||||
public function edit($id){
|
||||
$producto = Product::find($id);
|
||||
return view('productos.edit', compact('producto'));
|
||||
}
|
||||
|
||||
public function store(Request $request){
|
||||
$request->validate([
|
||||
'nombre' => 'required',
|
||||
'marca' => 'required',
|
||||
'modelo' => 'required',
|
||||
'descripcion' => 'required',
|
||||
'rodado' => 'required',
|
||||
'color' => 'required',
|
||||
'tipo' => 'required',
|
||||
'precio' => 'required'
|
||||
]);
|
||||
Product::create($request->all());
|
||||
|
||||
return redirect(route('productos.index'));
|
||||
}
|
||||
|
||||
public function update(Request $request,Product $producto){
|
||||
$request->validate([
|
||||
'nombre' => 'required',
|
||||
'marca' => 'required',
|
||||
'modelo' => 'required',
|
||||
'descripcion' => 'required',
|
||||
'rodado' => 'required',
|
||||
'color' => 'required',
|
||||
'tipo' => 'required',
|
||||
'precio' => 'required'
|
||||
]);
|
||||
$producto->update($request->all());
|
||||
return redirect(route('productos.show',$producto));
|
||||
}
|
||||
|
||||
public function destroy($id){
|
||||
$producto = Product::find($id);
|
||||
$producto->delete();
|
||||
return redirect(route('productos.index'));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Product extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
protected $fillable = [
|
||||
'nombre',
|
||||
'marca',
|
||||
'modelo',
|
||||
'rodado',
|
||||
'color',
|
||||
'tipo',
|
||||
'descripcion',
|
||||
'precio'
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\UserFactory> */
|
||||
use HasFactory, Notifiable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'password',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
/*
|
||||
* Get the attributes that should be cast.
|
||||
*
|
||||
* @return array<string, string>
|
||||
*/
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
/**
|
||||
* Register any application services.
|
||||
*/
|
||||
public function register(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Bootstrap any application services.
|
||||
*/
|
||||
public function boot(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace App\View\Components;
|
||||
|
||||
use Closure;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Illuminate\View\Component;
|
||||
|
||||
class Alert2 extends Component
|
||||
{
|
||||
public $class;
|
||||
//* Create a new component instance.
|
||||
public function __construct($type = 'dark')
|
||||
{
|
||||
switch ($type) {
|
||||
case 'info':
|
||||
$class = 'text-blue-800 bg-blue-50 dark:text-blue-400';
|
||||
break;
|
||||
case 'danger':
|
||||
$class = 'text-red-800 bg-red-50 dark:text-red-400';
|
||||
break;
|
||||
case 'success':
|
||||
$class = 'text-green-800 bg-green-50 dark:text-green-400';
|
||||
break;
|
||||
case 'warning':
|
||||
$class = 'text-yellow-800 bg-yellow-50 dark:text-yellow-300';
|
||||
break;
|
||||
default:
|
||||
$class = 'text-gray-800 bg-gray-50 dark:text-gray-300';
|
||||
break;
|
||||
}
|
||||
$this->class = $class;
|
||||
}
|
||||
|
||||
//* Get the view / contents that represent the component.
|
||||
public function render(): View|Closure|string
|
||||
{
|
||||
return view('components.alert2');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user