-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement assignment show lists, create, store
- Loading branch information
1 parent
d163860
commit c984061
Showing
12 changed files
with
230 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Models\Assignment; | ||
use App\Models\Classroom; | ||
use Illuminate\Http\Request; | ||
|
||
class AssignmentController extends Controller | ||
{ | ||
public function index(Classroom $classroom) { | ||
$assignments = Assignment::where('classroom_id', $classroom->id)->get(); | ||
|
||
return view('teacher.course.assignment', [ | ||
'classroom' => $classroom, | ||
'assignments' => $assignments | ||
]); | ||
} | ||
|
||
public function create(Classroom $classroom) { | ||
return view('teacher.class.createassignment', [ | ||
'classroom' => $classroom | ||
]); | ||
} | ||
|
||
public function createTask(Classroom $classroom) { | ||
return view('teacher.class.createtask'); | ||
} | ||
|
||
public function storeTask(Request $request, Classroom $classroom) { | ||
return 'stored task'; | ||
} | ||
|
||
public function createQuiz(Classroom $classroom) { | ||
return view('teacher.class.createquiztest', [ | ||
'classroom' => $classroom | ||
]); | ||
} | ||
|
||
public function storeQuiz(Request $request, Classroom $classroom) { | ||
$this->validate($request, [ | ||
'title' => 'required|max:255', | ||
'number_of_multiple_choice' => 'required|integer|max:10', | ||
'number_of_essay' => 'required|integer|max:10', | ||
]); | ||
|
||
$classroom->assignments()->create([ | ||
'title' => $request->title, | ||
'number_of_multiple_choice' => $request->number_of_multiple_choice, | ||
'number_of_essay' => $request->number_of_essay, | ||
'is_task' => false | ||
]); | ||
|
||
return redirect()->route('assignment', $classroom->id); | ||
} | ||
|
||
public function input(Classroom $classroom, Assignment $assignment) { | ||
return view('teacher.class.inputtask', [ | ||
'classroom' => $classroom, | ||
'assignment' => $assignment | ||
]); | ||
} | ||
|
||
public function storeInput(Request $request) { | ||
$this->validate($request, [ | ||
'question' => 'required' | ||
]); | ||
|
||
Assignment::create([ | ||
'question' => $request->question | ||
]); | ||
|
||
return redirect()->route('assignment'); | ||
} | ||
|
||
public function show(Classroom $classroom) { | ||
return 'show single task or quiz'; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Assignment extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $fillable = [ | ||
'title', | ||
'number_of_multiple_choice', | ||
'number_of_essay', | ||
'is_task', | ||
]; | ||
|
||
protected $casts = [ | ||
'is_task' => 'boolean', | ||
'questions' => 'array' | ||
]; | ||
|
||
public function classroom() { | ||
return $this->belongsTo(Classroom::class); | ||
} | ||
|
||
public function path() { | ||
return "/teacher/classroom/{$this->classroom->id}/assignment/{$this->id}"; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
database/migrations/2020_12_03_021722_create_assignments_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class CreateAssignmentsTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('assignments', function (Blueprint $table) { | ||
$table->id(); | ||
$table->string('title'); | ||
$table->unsignedSmallInteger('number_of_multiple_choice'); | ||
$table->unsignedSmallInteger('number_of_essay'); | ||
$table->boolean('is_task'); | ||
$table->json('questions')->nullable(); | ||
|
||
$table->foreignId('classroom_id')->constrained()->onDelete('cascade'); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('assignments'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.