Model y migration (estandar plan evidencia)

This commit is contained in:
cgonzalesmo 2022-07-08 22:09:04 -05:00
parent 76c606bd36
commit 8e7914bb38
21 changed files with 1369 additions and 11 deletions

File diff suppressed because it is too large Load Diff

BIN
.vs/PIS-proyect/v17/.suo Normal file

Binary file not shown.

3
.vs/ProjectSettings.json Normal file
View File

@ -0,0 +1,3 @@
{
"CurrentProjectSetting": null
}

10
.vs/VSWorkspaceState.json Normal file
View File

@ -0,0 +1,10 @@
{
"ExpandedNodes": [
"",
"\\app",
"\\app\\Models",
"\\app\\Providers"
],
"SelectedNode": "\\app\\Providers\\AppServiceProvider.php",
"PreviewInSolutionExplorer": false
}

3
.vs/phptasks.json Normal file
View File

@ -0,0 +1,3 @@
{
"tasks": []
}

BIN
.vs/slnx.sqlite Normal file

Binary file not shown.

View File

@ -0,0 +1,92 @@
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Models\Estandar;
use Illuminate\Support\Facades\DB;
class EstandarController extends Controller
{
public function createEstandar(Request $request){
$request->validate([
"name"=>"required",
]);
$id_user = auth()->user()->id;
$estandar = new Estandar();
$estandar->id_user = $id_user;
$estandar->name = $request->name;
$estandar->save();
return response([
"status" => 1,
"msg" => "!Estandar creado exitosamente",
]);
}
public function listEstandar(){
$estandares = Estandar::all();
return response([
"status" => 1,
"msg" => "!Lista de Estandares",
"data" => $estandares,
]);
}
public function showEstandar($id){
if(Estandar::where("id",$id)->exists()){
$estandar = Estandar::find($id);
return response([
"status" => 1,
"msg" => "!Estandar",
"data" => $estandar,
]);
}
else{
return response([
"status" => 0,
"msg" => "!No se encontro el estandar",
],404);
}
}
public function updateEstandar(Request $request, $id){
$id_user = auth()->user()->id;
if(Estandar::where(["id_user"=>$id_user,"id"=>$id])->exists()){
$estandar = Estandar::find($id);
$estandar->name = isset($request->name) ? $request->name : $estandar->title;
$estandar->save();
return response([
"status" => 1,
"msg" => "!Estandar actualizado",
"data" => $estandar,
]);
}
else{
return response([
"status" => 0,
"msg" => "!No se encontro el estandar o no esta autorizado",
],404);
}
}
public function deleteEstandar($id){
$id_user = auth()->user()->id;
if(Estandar::where(["id"=>$id,"id_user"=>$id_user])->exists()){
$estandar = Estandar::where(["id"=>$id,"id_user"=>$id_user])->first();
$estandar->delete();
return response([
"status" => 1,
"msg" => "!Estandar eliminado",
]);
}
else{
return response([
"status" => 0,
"msg" => "!No se encontro el estandar o no esta autorizado",
],404);
}
}
}

View File

@ -12,12 +12,14 @@ class UserController extends Controller
public function register(Request $request){ public function register(Request $request){
$request->validate([ $request->validate([
'name'=>'required', 'name'=>'required',
'lastname'=>'required',
'email'=>'required|email|unique:users', 'email'=>'required|email|unique:users',
'password'=>'required|confirmed' 'password'=>'required|confirmed'
]); ]);
$user = new User(); $user = new User();
$user->name = $request->name; $user->name = $request->name;
$user->lastname = $request->lastname;
$user->email = $request->email; $user->email = $request->email;
$user->password = Hash::make($request->password); $user->password = Hash::make($request->password);
$user->save(); $user->save();

View File

@ -7,5 +7,23 @@
class Estandar extends Model class Estandar extends Model
{ {
use HasFactory; use HasFactory;
public $timestamps = false;
protected $table ='estandars';
protected $fillable = [
'name',
];
public function users(){
return $this->belongsTo(User::class,'id_user');
}
public function plans(){
return $this->hasMany(Plan::class,'id');
}
public function evidencias(){
return $this->hasMany(Evidencia::class,'id');
}
} }

View File

@ -17,10 +17,21 @@ class User extends Authenticatable
protected $fillable = [ protected $fillable = [
'name', 'name',
'lastname',
'email', 'email',
'password', 'password',
]; ];
public $timestamps = false; public $timestamps = false;
public function estandars(){
return $this->hasMany(Estandar::class,'id');
}
public function plans(){
return $this->hasMany(Plan::class,'id');
}
public function evidencias(){
return $this->hasMany(Evidencia::class,'id');
}
} }

30
app/Models/evidencia.php Normal file
View File

@ -0,0 +1,30 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class evidencia extends Model
{
use HasFactory;
public $timestamps = false;
protected $table ='evidencias';
protected $fillable = [
'codigo',
'denominacion',
'adjunto',
];
public function users(){
return $this->belongsTo(User::class,'id_user');
}
public function estandars(){
return $this->belongsTo(Estandar::class,'id_estandar');
}
}

34
app/Models/plan.php Normal file
View File

@ -0,0 +1,34 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class plan extends Model
{
use HasFactory;
public $timestamps = false;
protected $table ='plans';
protected $fillable = [
'codigo',
'name',
'oportunidad',
'semestre',
'duracion',
'estado',
'avance',
'evaluacion',
];
public function users(){
return $this->belongsTo(User::class,'id_user');
}
public function estandars(){
return $this->belongsTo(Estandar::class,'id_estandar');
}
}

11
app/Models/role.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 role extends Model
{
use HasFactory;
}

View File

@ -16,6 +16,7 @@ public function up()
Schema::create('users', function (Blueprint $table) { Schema::create('users', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('name'); $table->string('name');
$table->string('lastname');
$table->string('email')->unique(); $table->string('email')->unique();
$table->string('password'); $table->string('password');
}); });

View File

@ -16,9 +16,9 @@ public function up()
Schema::create('estandars', function (Blueprint $table) { Schema::create('estandars', function (Blueprint $table) {
$table->id(); $table->id();
$table->string('name'); $table->string('name');
//$table->foreign('id_user')->references('id')->on('users');
$table->foreignId('id_user')
$table->timestamps(); ->constrained('users');
}); });
} }

View File

@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('roles', function (Blueprint $table) {
$table->id();
$table->string('name');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('roles');
}
};

View File

@ -0,0 +1,41 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('plans', function (Blueprint $table) {
$table->id();
$table->string('codigo', 11);
$table->string('name');
$table->string('oportunidad');
$table->string('semestre', 6);
$table->integer('duracion');
$table->string('estado', 20);
$table->boolean('eficacia');
$table->foreignId('id_estandar')
->constrained('estandars');
$table->foreignId('id_user')
->constrained('users');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('plans');
}
};

View File

@ -0,0 +1,38 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('evidencias', function (Blueprint $table) {
$table->id();
$table->string('codigo', 16);
$table->string('denominacion');
$table->string('oportunidad');
$table->foreignId('id_user')
->constrained('users');
$table->foreignId('id_estandar')
->constrained('estandars');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('evidencias');
}
};

View File

@ -3,13 +3,30 @@
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Route; use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Api\UserController; use App\Http\Controllers\Api\UserController;
use App\Http\Controllers\Api\EstandarController;
Route::post('register', [UserController::class, 'register']); Route::post('register', [UserController::class, 'register']);
Route::post('login', [UserController::class, 'login']); Route::post('login', [UserController::class, 'login']);
Route::middleware("auth:sanctum")->group (function(){ Route::middleware("auth:sanctum")->group (function(){
//rutas auth
Route::get('user-profile', [UserController::class,'userProfile']); Route::get('user-profile', [UserController::class,'userProfile']);
Route::get('logout', [UserController::class, 'logout']); Route::get('logout', [UserController::class, 'logout']);
//rutas estandar
Route::post('estandar', [EstandarController::class,'createEstandar']);
Route::get('estandar', [EstandarController::class,'listEstandar']);
Route::get('estandar/{id}', [EstandarController::class,'showEstandar']);
Route::put('estandar/{id}', [EstandarController::class,'updateEstandar']);
Route::delete('estandar/{id}', [EstandarController::class,'deleteEstandar']);
/*Route::controller(EstandarController::class)->group(function(){
Route::post('estandar/create', 'createEstandar');
Route::get('estandar/list', 'listEstandar');
Route::get('estandar/{id}', 'showEstandar');
Route::put('estandar/update/{id}', 'updateEstandar');
Route::delete('estandar/delete/{id}', 'deleteEstandar');
});*/
}); });
Route::middleware('auth:sanctum')->get('/user', function (Request $request) { Route::middleware('auth:sanctum')->get('/user', function (Request $request) {