issue #5: Creato migration per generalizzazione documenti e funzioni sul model GenDoc
This commit is contained in:
parent
b852a8e753
commit
44c27a9520
10
app/Http/Controllers/GenDocController.php
Normal file
10
app/Http/Controllers/GenDocController.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class GenDocController extends Controller
|
||||
{
|
||||
//
|
||||
}
|
43
app/Models/GenDoc.php
Normal file
43
app/Models/GenDoc.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
class GenDoc extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
// DocumentiGenerali
|
||||
|
||||
public static function saveDocument($entity,$entity_id,$data){
|
||||
|
||||
$filename=$data->file('filename')->store('Documenti');
|
||||
DB::table('gen_docs')
|
||||
->insert([
|
||||
'entity'=>$entity,
|
||||
'entity_id'=>$data->input('id'),
|
||||
'descrizione'=>$data->input('descrizione'),
|
||||
'filename'=>$filename,
|
||||
]);
|
||||
}
|
||||
|
||||
public static function listDocument($entity,$entity_id)
|
||||
{
|
||||
// Ritorna la lista dei documenti in base all'entità e al rispettivo id
|
||||
return DB::table('gen_docs')->where('entity','=',$entity)->andWere('entity_id','=',$entity_id)->get();
|
||||
}
|
||||
|
||||
public static function countDocument($entity,$entity_id){
|
||||
// Conta i documenti inseriti per la determinata entità e id
|
||||
$quanti=DB::table('gen_docs')
|
||||
->where('entity','=',$entity)
|
||||
->andWhere('entity_id','=',$entity_id)
|
||||
->count();
|
||||
return $quanti;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateGenDocsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('gen_docs', function (Blueprint $table) {
|
||||
// Documenti generali definibili agganciabili a diverse entità
|
||||
$table->id();
|
||||
$table->timestamps();
|
||||
$table->integer('entity')->unsigned();
|
||||
$table->bigInteger('entity_id');
|
||||
$table->string('filename', 255);
|
||||
$table->longText('descrizone');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('gen_docs');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user