Add function insert name and translation into DB
This commit is contained in:
@@ -4,6 +4,9 @@ namespace App\Http\Controllers;
|
|||||||
|
|
||||||
use App\Models\Word;
|
use App\Models\Word;
|
||||||
|
|
||||||
|
use Illuminate\Http\RedirectResponse;
|
||||||
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
class WordsController extends Controller
|
class WordsController extends Controller
|
||||||
{
|
{
|
||||||
public function index()
|
public function index()
|
||||||
@@ -12,4 +15,24 @@ class WordsController extends Controller
|
|||||||
'words' => Word::all(),
|
'words' => Word::all(),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Store a new Word in the database.
|
||||||
|
*/
|
||||||
|
public function store(Request $request): RedirectResponse
|
||||||
|
{
|
||||||
|
// Validate the request...
|
||||||
|
|
||||||
|
$word = new Word;
|
||||||
|
|
||||||
|
$word->name = $request->name;
|
||||||
|
$word->translation = $request->translation;
|
||||||
|
|
||||||
|
//$word->name = $request->input('name');
|
||||||
|
//$word->translation = $request->input('translation');
|
||||||
|
|
||||||
|
$word->save();
|
||||||
|
|
||||||
|
return redirect('/words');
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,4 +8,5 @@ use Illuminate\Database\Eloquent\Model;
|
|||||||
class Word extends Model
|
class Word extends Model
|
||||||
{
|
{
|
||||||
use HasFactory;
|
use HasFactory;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,5 +1,5 @@
|
|||||||
{
|
{
|
||||||
"name": "motula-translate",
|
"name": "Motula-Translate-Backend",
|
||||||
"lockfileVersion": 3,
|
"lockfileVersion": 3,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"packages": {
|
"packages": {
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr>
|
<tr>
|
||||||
<th>Word</th>
|
<th>Italian Word</th>
|
||||||
<th>Translation</th>
|
<th>Dialect Translation</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
|
|||||||
@@ -18,6 +18,12 @@
|
|||||||
<span class="link-title">Dashboard</span>
|
<span class="link-title">Dashboard</span>
|
||||||
</a>
|
</a>
|
||||||
</li>
|
</li>
|
||||||
|
<li class="nav-item">
|
||||||
|
<a href="{{route('words.index')}}" class="nav-link">
|
||||||
|
<i class="link-icon" data-feather="book"></i>
|
||||||
|
<span class="link-title">Table Words</span>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
<li class="nav-item nav-category">web apps</li>
|
<li class="nav-item nav-category">web apps</li>
|
||||||
<li class="nav-item">
|
<li class="nav-item">
|
||||||
<a class="nav-link" data-bs-toggle="collapse" href="#emails" role="button" aria-expanded="false"
|
<a class="nav-link" data-bs-toggle="collapse" href="#emails" role="button" aria-expanded="false"
|
||||||
|
|||||||
@@ -20,7 +20,25 @@
|
|||||||
{{-- @endforelse--}}
|
{{-- @endforelse--}}
|
||||||
{{-- </tbody>--}}
|
{{-- </tbody>--}}
|
||||||
{{-- </table>--}}
|
{{-- </table>--}}
|
||||||
|
<x-slot name="header">
|
||||||
|
<h2 class="font-semibold text-xl text-gray-800 dark:text-gray-200 leading-tight">
|
||||||
|
{{ __('Table Words') }}
|
||||||
|
</h2>
|
||||||
|
</x-slot>
|
||||||
|
|
||||||
|
<div class="py-12">
|
||||||
<x-table :items="$words" :fields="array('name','translation')" />
|
<div class="max-w-7xl mx-auto sm:px-6 lg:px-8 space-y-6">
|
||||||
|
<div class="p-4 sm:p-8 bg-white dark:bg-gray-800 shadow sm:rounded-lg">
|
||||||
|
<div class="max-w-xl">
|
||||||
|
@include('words.partials.insert-word-form')
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
{{--<div class="p-4 sm:p-8 bg-white dark:bg-gray-800 shadow sm:rounded-lg">--}}
|
||||||
|
{{-- <div class="max-w-xl">--}}
|
||||||
|
{{-- @include('words.partials.modify-word-form')--}}
|
||||||
|
{{-- </div>--}}
|
||||||
|
{{--</div>--}}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<x-table :items="$words" :fields="array('name','translation')" />
|
||||||
</x-app-layout>
|
</x-app-layout>
|
||||||
|
|||||||
32
resources/views/words/partials/insert-word-form.blade.php
Normal file
32
resources/views/words/partials/insert-word-form.blade.php
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
<section>
|
||||||
|
<header>
|
||||||
|
<h2 class="text-lg font-medium text-gray-900 dark:text-gray-100">
|
||||||
|
{{ __('Insert Word') }}
|
||||||
|
</h2>
|
||||||
|
|
||||||
|
<p class="mt-1 text-sm text-gray-600 dark:text-gray-400">
|
||||||
|
{{ __("Enter the word Italian and its dialect translation") }}
|
||||||
|
</p>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<form method="post" action="{{ route('words.insert') }}" class="mt-6 space-y-6">
|
||||||
|
@csrf
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<x-input-label for="name" :value="__('Italian Word')" />
|
||||||
|
<x-text-input id="name" name="name" type="text" class="mt-1 block w-full" placeholder="Italian Word"/>
|
||||||
|
<x-input-error :messages="$errors->get('name')" class="mt-2" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div>
|
||||||
|
<x-input-label for="translation" :value="__('Dialect Word')" />
|
||||||
|
<x-text-input id="translation" name="translation" type="text" class="mt-1 block w-full" placeholder="Dialectic Word"/>
|
||||||
|
<x-input-error :messages="$errors->get('translation')" class="mt-2" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="flex items-center gap-4">
|
||||||
|
<button type="submit" class="btn btn-primary me-2">Submit</button>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</section>
|
||||||
@@ -53,6 +53,7 @@ Route::middleware('auth')->group(function () {
|
|||||||
|
|
||||||
Route::prefix('words')->group(function () {
|
Route::prefix('words')->group(function () {
|
||||||
Route::get('/', [WordsController::class, 'index'])->name('words.index');
|
Route::get('/', [WordsController::class, 'index'])->name('words.index');
|
||||||
|
Route::post('/', [WordsController::class, 'store'])->name('words.insert');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user