Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FEATURE ✨ Add Product, ProductType models, migrations & seeders #7

Merged
merged 12 commits into from
Jan 26, 2024
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
Loading