Commit 76bc95c5 authored by alissonalbuquerque's avatar alissonalbuquerque
Browse files

add correção de criação de PAD

parent cb0ebb12
...@@ -27,12 +27,10 @@ class DashboardController extends Controller ...@@ -27,12 +27,10 @@ class DashboardController extends Controller
} }
if($user->isTypeTeacher()) if($user->isTypeTeacher())
{ {
$userType = $user->profile(UserType::TEACHER);
$userPads = $userPads =
UserPad::initQuery() UserPad::initQuery()
->whereUser($userType->id) ->whereUser($user->id)
->wherePadStatus(Status::ATIVO) ->wherePadStatus(Status::ATIVO)
->get(); ->get();
......
...@@ -102,13 +102,13 @@ class PadController extends Controller ...@@ -102,13 +102,13 @@ class PadController extends Controller
foreach($users as $user) foreach($users as $user)
{ {
$userType = $user->profile(UserType::TEACHER); $profile = $user->profile(UserType::TEACHER);
if($userType) if($profile)
{ {
$userPad = new UserPad(); $userPad = new UserPad();
$userPad->pad_id = $model->id; $userPad->pad_id = $model->id;
$userPad->user_type_id = $userType->id; $userPad->user_id = $user->id;
$userPad->status = Status::ATIVO; $userPad->status = Status::ATIVO;
$userPad->save(); $userPad->save();
......
...@@ -16,10 +16,10 @@ class UserPad extends Model ...@@ -16,10 +16,10 @@ class UserPad extends Model
protected $table = 'user_pad'; protected $table = 'user_pad';
protected $fillable = ['id', 'user_type_id', 'pad_id', 'status']; protected $fillable = ['id', 'user_id', 'pad_id', 'status'];
public function user() { public function user() {
return $this->belongsTo(UserType::class); return $this->belongsTo(User::class);
} }
public function pad() { public function pad() {
......
...@@ -29,7 +29,7 @@ class UserPadQuery extends CustomQuery ...@@ -29,7 +29,7 @@ class UserPadQuery extends CustomQuery
*/ */
public function whereUser($user_type_id, $operator = '=') public function whereUser($user_type_id, $operator = '=')
{ {
$this->query = $this->query->where('user_type_id', $operator, $user_type_id); $this->query = $this->query->where('user_id', $operator, $user_type_id);
return self::$instance; return self::$instance;
} }
......
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class AlterUserPadTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('user_pad', function (Blueprint $table) {
$table->dropColumn('user_type_id');
$table->foreignId('user_id')->after('id');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('user_pad', function (Blueprint $table) {
$table->dropColumn('user_id');
$table->foreignId('user_type_id')->after('id');
});
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment