Products
This commit is contained in:
parent
74000681fc
commit
c6a21ca630
9 changed files with 80 additions and 19 deletions
|
@ -4,17 +4,15 @@ namespace App\Http\Controllers;
|
|||
|
||||
use App\Models\Product;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class ProductController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
|
||||
public function index()
|
||||
{
|
||||
//
|
||||
// TMP do something better at some point maybe idk
|
||||
return redirect()->route("product.create");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -24,7 +22,7 @@ class ProductController extends Controller
|
|||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
return view("product/create");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -35,7 +33,18 @@ class ProductController extends Controller
|
|||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
Log::debug($request);
|
||||
$request->validate([
|
||||
'name'=>'required',
|
||||
'description'=>'required',
|
||||
]);
|
||||
$product = new Product([
|
||||
'name' => $request->get("name"),
|
||||
'description' => $request->get("description")
|
||||
]);
|
||||
$product->save();
|
||||
//echo $product->uuid;
|
||||
return redirect()->route("product.show", [ 'product' => $product])->with("message", "Product created successfully");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -46,7 +55,7 @@ class ProductController extends Controller
|
|||
*/
|
||||
public function show(Product $product)
|
||||
{
|
||||
//
|
||||
return view("product/view", ["product" => $product]);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -69,7 +78,9 @@ class ProductController extends Controller
|
|||
*/
|
||||
public function update(Request $request, Product $product)
|
||||
{
|
||||
//
|
||||
$product->fill($request->all());
|
||||
$product->save();
|
||||
return redirect()->route("product.show", [ 'product' => $product])->with("message", "Product created successfully");
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -80,6 +91,8 @@ class ProductController extends Controller
|
|||
*/
|
||||
public function destroy(Product $product)
|
||||
{
|
||||
//
|
||||
echo $product;
|
||||
$product->delete();
|
||||
return redirect()->route("product.index");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,13 +8,11 @@ use Illuminate\Database\Eloquent\Model;
|
|||
class Product extends Model
|
||||
{
|
||||
use HasFactory, HasUUID;
|
||||
public $primaryKey = "uuid";
|
||||
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'description',
|
||||
'password',
|
||||
];
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@ class ProductFactory extends Factory
|
|||
public function definition()
|
||||
{
|
||||
return [
|
||||
'id' => $this->faker->unique()->uuid(),
|
||||
'uuid' => $this->faker->unique()->uuid(),
|
||||
'name' => $this->faker->productName(),
|
||||
'description' => $this->faker->text(10000),
|
||||
];
|
||||
|
|
|
@ -23,7 +23,7 @@ class UserFactory extends Factory
|
|||
public function definition()
|
||||
{
|
||||
return [
|
||||
'id' => (string) Str::uuid(),
|
||||
'uuid' => (string) Str::uuid(),
|
||||
'name' => $this->faker->name(),
|
||||
'email' => $this->faker->unique()->safeEmail(),
|
||||
'email_verified_at' => now(),
|
||||
|
|
|
@ -14,7 +14,7 @@ class CreateProductsTable extends Migration
|
|||
public function up()
|
||||
{
|
||||
Schema::create('products', function (Blueprint $table) {
|
||||
$table->uuid("id")->primary();
|
||||
$table->uuid("uuid")->primary()->unique();
|
||||
$table->string("name", 255);
|
||||
$table->string("description", 10000);
|
||||
$table->timestamps();
|
||||
|
|
|
@ -34,7 +34,7 @@ services:
|
|||
MYSQL_PASSWORD: '${DB_PASSWORD}'
|
||||
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
|
||||
volumes:
|
||||
- 'sailmysql:/var/lib/mysql'
|
||||
- './storage/mysql:/var/lib/mysql'
|
||||
networks:
|
||||
- sail
|
||||
healthcheck:
|
||||
|
|
25
resources/views/product/create.blade.php
Normal file
25
resources/views/product/create.blade.php
Normal file
|
@ -0,0 +1,25 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
<style>
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
@if(Session::has('success'))
|
||||
<div class="alert alert-success">
|
||||
{{Session::get('success')}}
|
||||
</div>
|
||||
@endif
|
||||
<div>
|
||||
<form method="post" action="./">
|
||||
<input type="text" name="name">
|
||||
<textarea name="description" id="" cols="30" rows="10"></textarea>
|
||||
<input type="submit">
|
||||
@csrf
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
22
resources/views/product/view.blade.php
Normal file
22
resources/views/product/view.blade.php
Normal file
|
@ -0,0 +1,22 @@
|
|||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Document</title>
|
||||
<style>
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div>
|
||||
<p>
|
||||
{{ $product }}
|
||||
</p>
|
||||
<form method="POST">
|
||||
<button type="submit">Delete</button>
|
||||
@method('DELETE')
|
||||
@csrf
|
||||
</form>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
|
@ -1,6 +1,7 @@
|
|||
<?php
|
||||
|
||||
use App\Http\Controllers\LoginController;
|
||||
use App\Http\Controllers\ProductController;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
|
@ -29,3 +30,5 @@ Route::view("/login", "login");
|
|||
Route::post('/login', [LoginController::class, "authenticate"])->name("login");
|
||||
Route::post('/register', [LoginController::class, "register"])->name("register");
|
||||
Route::any("/logout", [LoginController::class, "logout"])->name("logout");
|
||||
|
||||
Route::resource("product", ProductController::class);
|
||||
|
|
Loading…
Reference in a new issue