This commit is contained in:
@@ -0,0 +1,72 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
class TlaController extends Controller
|
||||||
|
{
|
||||||
|
public function store(Request $request): RedirectResponse
|
||||||
|
{
|
||||||
|
$request->validate([
|
||||||
|
'title' => 'required',
|
||||||
|
'body' => 'required',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$tla = new Tla($requestData);
|
||||||
|
|
||||||
|
$tla->save();
|
||||||
|
|
||||||
|
return redirect()->route('admin')->with('success', 'Record added!');
|
||||||
|
} //
|
||||||
|
|
||||||
|
public function destroy(Tla $tla): RedirectResponse
|
||||||
|
{
|
||||||
|
$tla->delete();
|
||||||
|
|
||||||
|
return redirect()->route('admin')->with('success', 'Record deleted');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function fetch_tla(Request $request)
|
||||||
|
{
|
||||||
|
$requiest->validate([
|
||||||
|
'language' => 'required',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$requestData = $request->all();
|
||||||
|
|
||||||
|
$tla = Tla::where('language', $requestData['language'])
|
||||||
|
->andWhere('used', date())
|
||||||
|
->firstOrFail();
|
||||||
|
|
||||||
|
return $tla;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function check_tla()
|
||||||
|
{
|
||||||
|
$request->validate([
|
||||||
|
'guess' => 'required',
|
||||||
|
'language' => 'required',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$guess_array = explode(' ', $guess);
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function update(Request $request, Tla $tla): RedirectResponse
|
||||||
|
{
|
||||||
|
$request->validate([
|
||||||
|
'title' => 'required',
|
||||||
|
'body' => 'required',
|
||||||
|
]);
|
||||||
|
|
||||||
|
$requestData = $request->all();
|
||||||
|
|
||||||
|
$tla->update($requestData);
|
||||||
|
|
||||||
|
$tla->save();
|
||||||
|
|
||||||
|
return redirect()->route('admin')->with('success', 'Record updated!');
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
|
||||||
|
class Tla extends Model
|
||||||
|
{
|
||||||
|
protected $table = 'tla';
|
||||||
|
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $fillable = ['abbreviation', 'hint', 'used'];
|
||||||
|
}
|
||||||
@@ -7,6 +7,7 @@ use Illuminate\Http\Request;
|
|||||||
|
|
||||||
return Application::configure(basePath: dirname(__DIR__))
|
return Application::configure(basePath: dirname(__DIR__))
|
||||||
->withRouting(
|
->withRouting(
|
||||||
|
api: __DIR__.'/../routes/api.php',
|
||||||
web: __DIR__.'/../routes/web.php',
|
web: __DIR__.'/../routes/web.php',
|
||||||
commands: __DIR__.'/../routes/console.php',
|
commands: __DIR__.'/../routes/console.php',
|
||||||
health: '/up',
|
health: '/up',
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use App\Models\Tla;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @extends Factory<Tla>
|
||||||
|
*/
|
||||||
|
class TlaFactory extends Factory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Define the model's default state.
|
||||||
|
*
|
||||||
|
* @return array<string, mixed>
|
||||||
|
*/
|
||||||
|
public function definition(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'abbreviation' => fake()->word() . ' ' . fake()->word() . ' ' . fake()->word(),
|
||||||
|
'hint' => fake()->word(),
|
||||||
|
'language' => fake()->randomElement(['hu', 'en']),
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
<?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('tla', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('abbreviation');
|
||||||
|
$table->string('hint')->nullable();
|
||||||
|
$table->enum('language', ['hu', 'en']);
|
||||||
|
$table->date('used')->nullable();
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('tla');
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -3,6 +3,7 @@
|
|||||||
namespace Database\Seeders;
|
namespace Database\Seeders;
|
||||||
|
|
||||||
use App\Models\User;
|
use App\Models\User;
|
||||||
|
use App\Models\Tla;
|
||||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||||
use Illuminate\Database\Seeder;
|
use Illuminate\Database\Seeder;
|
||||||
|
|
||||||
@@ -16,10 +17,11 @@ class DatabaseSeeder extends Seeder
|
|||||||
public function run(): void
|
public function run(): void
|
||||||
{
|
{
|
||||||
// User::factory(10)->create();
|
// User::factory(10)->create();
|
||||||
|
Tla::factory(30)->create();
|
||||||
|
/*
|
||||||
User::factory()->create([
|
User::factory()->create([
|
||||||
'name' => 'Test User',
|
'name' => 'Test User',
|
||||||
'email' => 'test@example.com',
|
'email' => 'test@example.com',
|
||||||
]);
|
]);*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Support\Facades\Route;
|
||||||
|
|
||||||
|
Route::resource('people', \App\Http\Controllers\TlaController::class);
|
||||||
Reference in New Issue
Block a user