Compare commits
No commits in common. "2b945a5243990593408a479cdbeca9f5cd549db1" and "7cba5c3ebd70bb75fec27eb6e3cd072a0b4eb105" have entirely different histories.
2b945a5243
...
7cba5c3ebd
@ -1,63 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Http\Controllers;
|
|
||||||
|
|
||||||
use App\Models\Template;
|
|
||||||
use Illuminate\Http\Request;
|
|
||||||
|
|
||||||
class TemplateController extends Controller
|
|
||||||
{
|
|
||||||
// Get all templates
|
|
||||||
public function index()
|
|
||||||
{
|
|
||||||
return Template::with('kategori')->get();
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store template
|
|
||||||
public function store(Request $request)
|
|
||||||
{
|
|
||||||
$validated = $request->validate([
|
|
||||||
'kategori_id' => 'required|exists:kategoris,id',
|
|
||||||
'nama_template' => 'required|string|max:255',
|
|
||||||
'fitur' => 'nullable|string',
|
|
||||||
'foto' => 'nullable|string',
|
|
||||||
]);
|
|
||||||
|
|
||||||
|
|
||||||
$template = Template::create($validated);
|
|
||||||
|
|
||||||
return response()->json($template, 201);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Show template by id
|
|
||||||
public function show($id)
|
|
||||||
{
|
|
||||||
return Template::with('kategori')->findOrFail($id);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update template
|
|
||||||
public function update(Request $request, $id)
|
|
||||||
{
|
|
||||||
$template = Template::findOrFail($id);
|
|
||||||
|
|
||||||
$validated = $request->validate([
|
|
||||||
'id_kategori' => 'required|exists:kategori,id_kategori',
|
|
||||||
'nama_template' => 'required|string|max:255',
|
|
||||||
'fitur' => 'nullable|string',
|
|
||||||
'foto' => 'nullable|string',
|
|
||||||
]);
|
|
||||||
|
|
||||||
$template->update($validated);
|
|
||||||
|
|
||||||
return response()->json($template);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delete template
|
|
||||||
public function destroy($id)
|
|
||||||
{
|
|
||||||
$template = Template::findOrFail($id);
|
|
||||||
$template->delete();
|
|
||||||
|
|
||||||
return response()->json(null, 204);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,34 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace App\Models;
|
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
||||||
use Illuminate\Database\Eloquent\Model;
|
|
||||||
|
|
||||||
class Template extends Model
|
|
||||||
{
|
|
||||||
use HasFactory;
|
|
||||||
|
|
||||||
protected $table = 'templates';
|
|
||||||
protected $primaryKey = 'id_template';
|
|
||||||
|
|
||||||
protected $fillable = [
|
|
||||||
'kategori_id',
|
|
||||||
'nama_template',
|
|
||||||
'fitur',
|
|
||||||
'foto',
|
|
||||||
];
|
|
||||||
|
|
||||||
|
|
||||||
// Relasi ke kategori
|
|
||||||
public function kategori()
|
|
||||||
{
|
|
||||||
return $this->belongsTo(Kategori::class, 'kategori_id');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Relasi ke pemesanan
|
|
||||||
public function pemesanan()
|
|
||||||
{
|
|
||||||
return $this->hasMany(Pemesanan::class, 'id_template', 'id_template');
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
namespace Database\Factories;
|
|
||||||
|
|
||||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Template>
|
|
||||||
*/
|
|
||||||
class TemplateFactory extends Factory
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Define the model's default state.
|
|
||||||
*
|
|
||||||
* @return array<string, mixed>
|
|
||||||
*/
|
|
||||||
public function definition(): array
|
|
||||||
{
|
|
||||||
return [
|
|
||||||
//
|
|
||||||
];
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,35 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
use Illuminate\Database\Migrations\Migration;
|
|
||||||
use Illuminate\Database\Schema\Blueprint;
|
|
||||||
use Illuminate\Support\Facades\Schema;
|
|
||||||
|
|
||||||
return new class extends Migration
|
|
||||||
{
|
|
||||||
/**
|
|
||||||
* Run the migrations.
|
|
||||||
*/
|
|
||||||
public function up(): void
|
|
||||||
{
|
|
||||||
Schema::create('templates', function (Blueprint $table) {
|
|
||||||
$table->id('id_template'); // Primary Key
|
|
||||||
$table->unsignedBigInteger('id_kategori'); // Foreign Key ke kategori
|
|
||||||
$table->string('nama_template');
|
|
||||||
$table->text('fitur')->nullable();
|
|
||||||
$table->string('foto')->nullable();
|
|
||||||
$table->timestamps();
|
|
||||||
|
|
||||||
// Relasi ke tabel kategori
|
|
||||||
$table->unsignedBigInteger('kategori_id');
|
|
||||||
$table->foreign('kategori_id')->references('id')->on('kategoris')->onDelete('cascade');
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Reverse the migrations.
|
|
||||||
*/
|
|
||||||
public function down(): void
|
|
||||||
{
|
|
||||||
Schema::dropIfExists('templates');
|
|
||||||
}
|
|
||||||
};
|
|
@ -3,8 +3,6 @@
|
|||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Route;
|
use Illuminate\Support\Facades\Route;
|
||||||
use App\Http\Controllers\Api\ReviewController;
|
use App\Http\Controllers\Api\ReviewController;
|
||||||
use App\Http\Controllers\TemplateController;
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|--------------------------------------------------------------------------
|
|--------------------------------------------------------------------------
|
||||||
@ -18,4 +16,3 @@ use App\Http\Controllers\TemplateController;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
Route::apiResource('reviews', ReviewController::class);
|
Route::apiResource('reviews', ReviewController::class);
|
||||||
Route::apiResource('templates', TemplateController::class);
|
|
||||||
|
Loading…
Reference in New Issue
Block a user