Add file upload function. modify paramiter FILESYSTEM_DISK=public in file .env

This commit is contained in:
paoloGuagnano
2024-02-11 18:25:29 +01:00
parent f69f2ba046
commit 0cedec9711
10 changed files with 240 additions and 3 deletions

View File

@@ -0,0 +1,32 @@
<?php
namespace App\Http\Controllers;
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(Request $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());
$filename = 'new_file.'.$request->filename->extension();
$request->filename->storeAs('file_temp', $filename);
return redirect('/words');
}
public function delete(): RedirectResponse
{
Storage::delete('file_temp/new_file.txt');
return redirect('/words');
}
}

View 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 [
//
];
}
}

View 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 [
//
];
}
}

11
app/Models/file.php Normal file
View 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;
}

View 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
{
//
}
}