Merge remote-tracking branch 'origin/main'
# Conflicts: # routes/web.php
This commit is contained in:
39
app/Http/Controllers/FileController.php
Normal file
39
app/Http/Controllers/FileController.php
Normal file
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\FileRequest;
|
||||
use App\Http\Requests\StorefileRequest;
|
||||
use App\Http\Requests\UpdatefileRequest;
|
||||
use App\Models\file;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class FileController extends Controller
|
||||
{
|
||||
public function datasubmit(FileRequest $request): RedirectResponse
|
||||
{
|
||||
//upload file in public folder
|
||||
//dd($reqest->all());
|
||||
//$filename = 'new_file.'.$request->filename->extension();
|
||||
//$request->filename->move(public_path('uploads'), $filename);
|
||||
|
||||
//dd($request->all());
|
||||
//$request->validate([
|
||||
// 'filename'=>'required'
|
||||
//]);
|
||||
|
||||
$filename = 'new_file.'.$request->file("filetoinsert")->getClientOriginalExtension();
|
||||
$request->file("filetoinsert")->storeAs('file_temp', $filename);
|
||||
|
||||
//$request->filename->storeAs('file_temp', $filename);
|
||||
return redirect('/words');
|
||||
}
|
||||
|
||||
public function delete(): RedirectResponse
|
||||
{
|
||||
Storage::delete('file_temp/new_file.txt');
|
||||
return redirect('/words');
|
||||
}
|
||||
}
|
||||
@@ -2,11 +2,11 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Http\Requests\WordRequest;
|
||||
use App\Models\Word;
|
||||
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class WordsController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
@@ -25,20 +25,49 @@ class WordsController extends Controller
|
||||
/**
|
||||
* Store a new Word in the database.
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
public function store(WordRequest $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');
|
||||
}
|
||||
|
||||
/**
|
||||
* Update an existing Word in the database.
|
||||
*/
|
||||
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(WordRequest $request, $id): RedirectResponse
|
||||
{
|
||||
$data = Word::find($id);
|
||||
|
||||
$data->name = $request->name;
|
||||
$data->translation = $request->translation;
|
||||
$data->save();
|
||||
|
||||
return redirect('/words');
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete an existing Word in the database.
|
||||
*/
|
||||
public function delete($id): RedirectResponse
|
||||
{
|
||||
Word::destroy($id);
|
||||
return redirect('/words');
|
||||
}
|
||||
}
|
||||
|
||||
42
app/Http/Requests/FileRequest.php
Normal file
42
app/Http/Requests/FileRequest.php
Normal file
@@ -0,0 +1,42 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Rules\File;
|
||||
|
||||
|
||||
class FileRequest extends FormRequest
|
||||
{
|
||||
public $filetoinsert;
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
'filetoinsert' => ['required', 'mimes:txt']//, File::types(['csv'])]
|
||||
];
|
||||
}
|
||||
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'filetoinsert.required' => 'ERROR: csv file not selected!',
|
||||
'filetoinsert.mimes'=> "ERRORE: select only csv format"
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
28
app/Http/Requests/StorefileRequest.php
Normal file
28
app/Http/Requests/StorefileRequest.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class StorefileRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
app/Http/Requests/UpdatefileRequest.php
Normal file
28
app/Http/Requests/UpdatefileRequest.php
Normal file
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
|
||||
class UpdatefileRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -10,10 +10,19 @@ class WordRequest extends FormRequest
|
||||
{
|
||||
return [
|
||||
'name' => ['required'],
|
||||
'translation' => ['required'],
|
||||
'translation' => ['required', 'unique:words,translation'],
|
||||
];
|
||||
}
|
||||
|
||||
public function messages(): array
|
||||
{
|
||||
return [
|
||||
'name.required' => 'Insert italian Word',
|
||||
'translation.required' => 'Insert dialect Word',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
public function authorize(): bool
|
||||
{
|
||||
return true;
|
||||
|
||||
@@ -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;
|
||||
|
||||
11
app/Models/file.php
Normal file
11
app/Models/file.php
Normal file
@@ -0,0 +1,11 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class file extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
}
|
||||
66
app/Policies/FilePolicy.php
Normal file
66
app/Policies/FilePolicy.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\Models\User;
|
||||
use App\Models\file;
|
||||
use Illuminate\Auth\Access\Response;
|
||||
|
||||
class FilePolicy
|
||||
{
|
||||
/**
|
||||
* Determine whether the user can view any models.
|
||||
*/
|
||||
public function viewAny(User $user): bool
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can view the model.
|
||||
*/
|
||||
public function view(User $user, file $file): bool
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can create models.
|
||||
*/
|
||||
public function create(User $user): bool
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can update the model.
|
||||
*/
|
||||
public function update(User $user, file $file): bool
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can delete the model.
|
||||
*/
|
||||
public function delete(User $user, file $file): bool
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can restore the model.
|
||||
*/
|
||||
public function restore(User $user, file $file): bool
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine whether the user can permanently delete the model.
|
||||
*/
|
||||
public function forceDelete(User $user, file $file): bool
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
23
database/factories/FileFactory.php
Normal file
23
database/factories/FileFactory.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\file>
|
||||
*/
|
||||
class FileFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
||||
27
database/migrations/2024_02_10_195359_create_files_table.php
Normal file
27
database/migrations/2024_02_10_195359_create_files_table.php
Normal file
@@ -0,0 +1,27 @@
|
||||
<?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('files', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('files');
|
||||
}
|
||||
};
|
||||
17
database/seeders/FileSeeder.php
Normal file
17
database/seeders/FileSeeder.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
|
||||
class FileSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
@props(['messages'])
|
||||
|
||||
@if ($messages)
|
||||
<ul {{ $attributes->merge(['class' => 'text-danger text-sm text-red-600 dark:text-red-400 space-y-1']) }}>
|
||||
<ul {{ $attributes->merge(['class' => 'alert alert-danger text-sm text-red-600 dark:text-red-400 space-y-1']) }}>
|
||||
@foreach ((array) $messages as $message)
|
||||
<li>{{ $message }}</li>
|
||||
@endforeach
|
||||
|
||||
@@ -14,6 +14,8 @@
|
||||
<tr>
|
||||
<td>{{ $item->{$fields[0]} }}</td>
|
||||
<td>{{ $item->{$fields[1]} }}</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
|
||||
<tr>
|
||||
|
||||
@@ -1,25 +1,4 @@
|
||||
<x-app-layout>
|
||||
{{-- <table class="table table-striped">--}}
|
||||
{{-- <thead>--}}
|
||||
{{-- <tr>--}}
|
||||
{{-- <th>Word</th>--}}
|
||||
{{-- <th>Translation</th>--}}
|
||||
{{-- </tr>--}}
|
||||
{{-- </thead>--}}
|
||||
{{-- <tbody>--}}
|
||||
|
||||
{{-- @forelse ($words as $word)--}}
|
||||
{{-- <tr>--}}
|
||||
{{-- <td>{{$word->name}}</td>--}}
|
||||
{{-- <td>{{$word->translation}}</td>--}}
|
||||
{{-- </tr>--}}
|
||||
{{-- @empty--}}
|
||||
{{-- <tr>--}}
|
||||
{{-- <td class="text-center" colspan="2">No words</td>--}}
|
||||
{{-- </tr>--}}
|
||||
{{-- @endforelse--}}
|
||||
{{-- </tbody>--}}
|
||||
{{-- </table>--}}
|
||||
<x-slot name="header">
|
||||
<h2 class="font-semibold text-xl text-gray-800 dark:text-gray-200 leading-tight">
|
||||
{{ __('Table Words') }}
|
||||
@@ -27,17 +6,29 @@
|
||||
</x-slot>
|
||||
|
||||
<div class="py-12">
|
||||
<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 class="row">
|
||||
<div class="col-lg-7 col-xl-8 grid-margin stretch-card">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<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>
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-lg-5 col-xl-4 grid-margin stretch-card">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<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.upload-file')
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</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')" />
|
||||
|
||||
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>
|
||||
@@ -14,19 +14,18 @@
|
||||
|
||||
<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-text-input id="name" name="name" type="text" class="mt-1 block w-full" placeholder="Italian Word" 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" type="text" class="mt-1 block w-full" placeholder="Dialectic Word"/>
|
||||
<x-text-input id="translation" name="translation" type="text" class="mt-1 block w-full" placeholder="Dialectic Word" autofocus autocomplete="translation" />
|
||||
<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>
|
||||
|
||||
<x-primary-button>{{ __('Submit') }}</x-primary-button>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
|
||||
|
||||
22
resources/views/words/partials/upload-file.blade.php
Normal file
22
resources/views/words/partials/upload-file.blade.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<section>
|
||||
<header>
|
||||
<h2 class="text-lg font-medium text-gray-900 dark:text-gray-100">
|
||||
{{ __('Upload CSV File ') }}
|
||||
</h2>
|
||||
|
||||
<p class="mt-1 text-sm text-gray-600 dark:text-gray-400">
|
||||
{{ __("Upload file to add group of word in db") }}
|
||||
</p>
|
||||
</header>
|
||||
|
||||
<form action="{{ route('store') }}" method="post" class="mt-6 space-y-6" enctype="multipart/form-data">
|
||||
@csrf
|
||||
|
||||
<x-text-input type="file" id="filetoinsert" name="filetoinsert"/>
|
||||
<x-input-error class="mt-2" :messages="$errors->get('filetoinsert')" />
|
||||
<div class="flex items-center gap-4">
|
||||
<br>
|
||||
<x-primary-button>{{ __('Submit') }}</x-primary-button>
|
||||
</div>
|
||||
</form>
|
||||
</section>
|
||||
@@ -4,6 +4,7 @@ use App\Http\Controllers\ProfileController;
|
||||
use App\Http\Controllers\RolesController;
|
||||
use App\Http\Controllers\UsersController;
|
||||
use App\Http\Controllers\WordsController;
|
||||
use App\Http\Controllers\FileController;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
@@ -60,6 +61,13 @@ Route::prefix('words')->group(function () {
|
||||
Route::post('/', [WordsController::class, 'store'])->name('words.insert');
|
||||
});
|
||||
|
||||
Route::get('delete_record/{id}', [WordsController::class, 'delete']);
|
||||
Route::get('edit_record/{id}', [WordsController::class, 'edit']);
|
||||
Route::post('update_record/{id}', [WordsController::class, 'update'])->name('words.update');;
|
||||
|
||||
//***** FILE *****\\
|
||||
Route::post('datasubmit', [FileController::class, 'datasubmit'])->name("store");
|
||||
|
||||
Route::resources([
|
||||
'roles' => RolesController::class,
|
||||
'users' => UsersController::class,
|
||||
|
||||
Reference in New Issue
Block a user