Add function get and modify italian words and dialectic word from DB
This commit is contained in:
@@ -6,7 +6,6 @@ use App\Models\Word;
|
||||
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class WordsController extends Controller
|
||||
{
|
||||
public function index()
|
||||
@@ -21,16 +20,9 @@ class WordsController extends Controller
|
||||
*/
|
||||
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');
|
||||
@@ -39,8 +31,26 @@ class WordsController extends Controller
|
||||
/**
|
||||
* Update an existing Word in the database.
|
||||
*/
|
||||
public function update(Request $request): RedirectResponse
|
||||
public function edit($id)
|
||||
{
|
||||
$data = Word::find($id);
|
||||
$id = $data->id;
|
||||
$name = $data->name;
|
||||
$translation = $data->translation;
|
||||
//return $translation;
|
||||
return view("words.modify-word-form", compact('id', "name", "translation"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing Word in the database.
|
||||
*/
|
||||
public function update(Request $request, $id): RedirectResponse
|
||||
{
|
||||
$data = Word::find($id);
|
||||
|
||||
$data->name = $request->name;
|
||||
$data->translation = $request->translation;
|
||||
$data->save();
|
||||
|
||||
return redirect('/words');
|
||||
}
|
||||
@@ -50,7 +60,7 @@ class WordsController extends Controller
|
||||
*/
|
||||
public function delete($id): RedirectResponse
|
||||
{
|
||||
word::destroy($id);
|
||||
Word::destroy($id);
|
||||
return redirect('/words');
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,6 +5,9 @@ namespace App\Models;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* @method static find($id)
|
||||
*/
|
||||
class Word extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<tr>
|
||||
<td>{{ $item->{$fields[0]} }}</td>
|
||||
<td>{{ $item->{$fields[1]} }}</td>
|
||||
<td> <a href=""><button class="btn btn-primary">Edit</button> </a> </td>
|
||||
<td> <a href="edit_record/{{ $item->id }}"><button class="btn btn-primary">Edit</button> </a> </td>
|
||||
<td> <a href="delete_record/{{ $item->id }}"><button class="btn btn-danger">Delete</button> </a> </td>
|
||||
</tr>
|
||||
@empty
|
||||
|
||||
32
resources/views/words/modify-word-form.blade.php
Normal file
32
resources/views/words/modify-word-form.blade.php
Normal file
@@ -0,0 +1,32 @@
|
||||
<x-app-layout>
|
||||
<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.update', $id) }}" class="mt-6 space-y-6">
|
||||
@csrf
|
||||
|
||||
<div>
|
||||
<x-input-label for="name" :value="__('Italian Word')" />
|
||||
<x-text-input id="name" name="name" value="{{$name}}" type="text" class="mt-1 block w-full" placeholder="Italian Word" required autofocus autocomplete="name"/>
|
||||
<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" value="{{$translation}}" type="text" class="mt-1 block w-full" placeholder="Dialectic Word" required autofocus autocomplete="translation" />
|
||||
<x-input-error :messages="$errors->get('translation')" class="mt-2" />
|
||||
</div>
|
||||
<div class="flex items-center gap-4">
|
||||
<x-primary-button>{{ __('Submit') }}</x-primary-button>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
</x-app-layout>
|
||||
@@ -28,3 +28,4 @@
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
|
||||
@@ -57,7 +57,8 @@ Route::prefix('words')->group(function () {
|
||||
});
|
||||
|
||||
Route::get('delete_record/{id}', [WordsController::class, 'delete']);
|
||||
//Route::get('delete_record/{id}', [WordsController::class, 'update']);
|
||||
Route::get('edit_record/{id}', [WordsController::class, 'edit']);
|
||||
Route::post('update_record/{id}', [WordsController::class, 'update'])->name('words.update');;
|
||||
|
||||
require __DIR__ . '/auth.php';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user