Skip to content

Commit

Permalink
FEATURE ✨ Add Product, ProductType models, migrations & seeders (#7)
Browse files Browse the repository at this point in the history
* Dep: Fix the php version

* feat: Add Migration for product

* feat: Add Factory and model for product

* feat: Add relation

* feat: Add Controller Requests and Policy

* feat: Add ProductType model

* fix: Fix relation with Product Type model

---------

Co-authored-by: Darián López Utra <[email protected]>
Co-authored-by: Nico Deblauwe <[email protected]>
  • Loading branch information
3 people authored Jan 26, 2024
1 parent 5ca1258 commit 1d37e0e
Show file tree
Hide file tree
Showing 13 changed files with 413 additions and 53 deletions.
67 changes: 67 additions & 0 deletions app/Http/Controllers/ProductController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

namespace App\Http\Controllers;

use App\Models\product;
use App\Http\Requests\StoreproductRequest;
use App\Http\Requests\UpdateproductRequest;

class ProductController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index()
{
//

}

/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}

/**
* Store a newly created resource in storage.
*/
public function store(StoreproductRequest $request)
{
//
}

/**
* Display the specified resource.
*/
public function show(product $product)
{
//
}

/**
* Show the form for editing the specified resource.
*/
public function edit(product $product)
{
//
}

/**
* Update the specified resource in storage.
*/
public function update(UpdateproductRequest $request, product $product)
{
//
}

/**
* Remove the specified resource from storage.
*/
public function destroy(product $product)
{
//
}
}
28 changes: 28 additions & 0 deletions app/Http/Requests/StoreproductRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class StoreproductRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
//
];
}
}
28 changes: 28 additions & 0 deletions app/Http/Requests/UpdateproductRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class UpdateproductRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
return [
//
];
}
}
23 changes: 23 additions & 0 deletions app/Models/Product.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Product extends Model
{
use HasFactory;

protected $fillable = [
'product_type_id',
'name',
'price_in_cents',
'description',
];

public function product_type()
{
return $this->belongsTo(product_type::class);
}
}
18 changes: 18 additions & 0 deletions app/Models/ProductType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class ProductType extends Model
{
use HasFactory;

protected $fillable = [
'name',
'time_unit',
'price_in_cents',
];

}
55 changes: 55 additions & 0 deletions app/Policies/ProductPolicy.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

namespace App\Policies;

use App\Models\User;
use App\Models\product;
use Illuminate\Auth\Access\Response;

class ProductPolicy
{
/**
* Determine whether the user can view any models.
*/
public function viewAny(User $user): bool
{
//
return true;
}

/**
* Determine whether the user can view the model.
*/
public function view(User $user, product $product): bool
{
//
return true;
}

/**
* Determine whether the user can create models.
*/
public function create(User $user): bool
{
//
return true;
}

/**
* Determine whether the user can update the model.
*/
public function update(User $user, product $product): bool
{
//
return true;
}

/**
* Determine whether the user can delete the model.
*/
public function delete(User $user, product $product): bool
{
//
return true;
}
}
7 changes: 5 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
"name": "ndeblauw/extra.harbourspace.site",
"type": "application",
"description": "A (demo) application for managing invoices.",
"keywords": ["laravel", "framework"],
"keywords": [
"laravel",
"framework"
],
"license": "MIT",
"require": {
"php": "^8.2",
Expand Down Expand Up @@ -69,4 +72,4 @@
},
"minimum-stability": "stable",
"prefer-stable": true
}
}
Loading

0 comments on commit 1d37e0e

Please sign in to comment.