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 App\Models\Product;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
use Illuminate\Support\Facades\Log;
|
||||||
|
|
||||||
class ProductController extends Controller
|
class ProductController extends Controller
|
||||||
{
|
{
|
||||||
/**
|
|
||||||
* Display a listing of the resource.
|
|
||||||
*
|
|
||||||
* @return \Illuminate\Http\Response
|
|
||||||
*/
|
|
||||||
public function index()
|
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()
|
public function create()
|
||||||
{
|
{
|
||||||
//
|
return view("product/create");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -35,7 +33,18 @@ class ProductController extends Controller
|
||||||
*/
|
*/
|
||||||
public function store(Request $request)
|
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)
|
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)
|
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)
|
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
|
class Product extends Model
|
||||||
{
|
{
|
||||||
use HasFactory, HasUUID;
|
use HasFactory, HasUUID;
|
||||||
|
public $primaryKey = "uuid";
|
||||||
|
|
||||||
|
|
||||||
protected $fillable = [
|
protected $fillable = [
|
||||||
'name',
|
'name',
|
||||||
'description',
|
'description',
|
||||||
'password',
|
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,7 +23,7 @@ class ProductFactory extends Factory
|
||||||
public function definition()
|
public function definition()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'id' => $this->faker->unique()->uuid(),
|
'uuid' => $this->faker->unique()->uuid(),
|
||||||
'name' => $this->faker->productName(),
|
'name' => $this->faker->productName(),
|
||||||
'description' => $this->faker->text(10000),
|
'description' => $this->faker->text(10000),
|
||||||
];
|
];
|
||||||
|
|
|
@ -23,7 +23,7 @@ class UserFactory extends Factory
|
||||||
public function definition()
|
public function definition()
|
||||||
{
|
{
|
||||||
return [
|
return [
|
||||||
'id' => (string) Str::uuid(),
|
'uuid' => (string) Str::uuid(),
|
||||||
'name' => $this->faker->name(),
|
'name' => $this->faker->name(),
|
||||||
'email' => $this->faker->unique()->safeEmail(),
|
'email' => $this->faker->unique()->safeEmail(),
|
||||||
'email_verified_at' => now(),
|
'email_verified_at' => now(),
|
||||||
|
|
|
@ -14,7 +14,7 @@ class CreateProductsTable extends Migration
|
||||||
public function up()
|
public function up()
|
||||||
{
|
{
|
||||||
Schema::create('products', function (Blueprint $table) {
|
Schema::create('products', function (Blueprint $table) {
|
||||||
$table->uuid("id")->primary();
|
$table->uuid("uuid")->primary()->unique();
|
||||||
$table->string("name", 255);
|
$table->string("name", 255);
|
||||||
$table->string("description", 10000);
|
$table->string("description", 10000);
|
||||||
$table->timestamps();
|
$table->timestamps();
|
||||||
|
|
|
@ -34,7 +34,7 @@ services:
|
||||||
MYSQL_PASSWORD: '${DB_PASSWORD}'
|
MYSQL_PASSWORD: '${DB_PASSWORD}'
|
||||||
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
|
MYSQL_ALLOW_EMPTY_PASSWORD: 'yes'
|
||||||
volumes:
|
volumes:
|
||||||
- 'sailmysql:/var/lib/mysql'
|
- './storage/mysql:/var/lib/mysql'
|
||||||
networks:
|
networks:
|
||||||
- sail
|
- sail
|
||||||
healthcheck:
|
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
|
<?php
|
||||||
|
|
||||||
use App\Http\Controllers\LoginController;
|
use App\Http\Controllers\LoginController;
|
||||||
|
use App\Http\Controllers\ProductController;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
|
@ -29,3 +30,5 @@ Route::view("/login", "login");
|
||||||
Route::post('/login', [LoginController::class, "authenticate"])->name("login");
|
Route::post('/login', [LoginController::class, "authenticate"])->name("login");
|
||||||
Route::post('/register', [LoginController::class, "register"])->name("register");
|
Route::post('/register', [LoginController::class, "register"])->name("register");
|
||||||
Route::any("/logout", [LoginController::class, "logout"])->name("logout");
|
Route::any("/logout", [LoginController::class, "logout"])->name("logout");
|
||||||
|
|
||||||
|
Route::resource("product", ProductController::class);
|
||||||
|
|
Loading…
Reference in a new issue