Skip to content
Merged
14 changes: 6 additions & 8 deletions plugins/rainlab/user/models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,7 @@ public function getAvatarThumb($size = 25, $options = null)
{
if (is_string($options)) {
$options = ['default' => $options];
}
elseif (!is_array($options)) {
} elseif (!is_array($options)) {
$options = [];
}

Expand All @@ -170,8 +169,7 @@ public function getAvatarThumb($size = 25, $options = null)

if ($this->avatar) {
return $this->avatar->getThumb($size, $size, $options);
}
else {
} else {
return '//www.gravatar.com/avatar/'.
md5(strtolower(trim($this->email))).
'?s='.$size.
Expand Down Expand Up @@ -212,7 +210,7 @@ public function scopeIsActivated($query)

public function scopeFilterByGroup($query, $filter)
{
return $query->whereHas('groups', function($group) use ($filter) {
return $query->whereHas('groups', function ($group) use ($filter) {
$group->whereIn('id', $filter);
});
}
Expand Down Expand Up @@ -275,7 +273,8 @@ public function beforeLogin()
if ($this->is_guest) {
$login = $this->getLogin();
throw new AuthException(sprintf(
'Cannot login user "%s" as they are not registered.', $login
'Cannot login user "%s" as they are not registered.',
$login
));
}

Expand All @@ -298,8 +297,7 @@ public function afterLogin()
]);

Event::fire('rainlab.user.reactivate', [$this]);
}
else {
} else {
parent::afterLogin();
}

Expand Down
8 changes: 7 additions & 1 deletion plugins/teachplusplus/teachers/models/Feedback.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,17 @@ class Feedback extends Model

/**
* @var string The database table used by the model.
*
*
*/
protected $fillable = [
'content'
];

public $table = 'teachplusplus_teachers_feedbacks';


public $hasOne =[
public $hasOne =[

'subject' => 'Teachplusplus\teachers\Models\Subject'
];
Expand Down
9 changes: 9 additions & 0 deletions plugins/teachplusplus/teachers/models/feedback/columns.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
columns:
id:
label: id
type: number
content:
label: Feedbacks
type: text
sortable: true
created_at:
label: created_at
type: datetime
updated_at:
label: updated_at
type: datetime
32 changes: 23 additions & 9 deletions plugins/teachplusplus/teachers/routes.php
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
<?php
use Teachplusplus\Teachers\Models\Teacher;
use Teachplusplus\Teachers\Models\Feedback;

Route::get('api/teacher', function () {

$teachers = Teacher::with('subjects', 'feedbacks')->get();
Route::group(['prefix' => 'api'], function () {
Route::get('teacher', function () {
$teachers = Teacher::with('subjects', 'feedbacks')->get();


return $teachers;
});

Route::get('api/teacher/{id}', function ($id) {
return $teachers;
});

$teacher = Teacher::with('subjects', 'feedbacks')->findOrFail($id);
Route::get('teacher/{id}', function ($id) {
$teacher = Teacher::with('subjects', 'feedbacks')->findOrFail($id);



return $teacher;
return $teacher;
});

Route::post('feedback', function () {
$data = request()->only([
'content'
]);
$teacherId = request()->input('teacher_id');

$teacher = Teacher::find($teacherId);

$feedback = Feedback::create($data);
$feedback->teacher()->associate($teacher);
$feedback->save();
});
});