-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #259 from changeweb/UploadCertificate
Add Certificate upload feature
- Loading branch information
Showing
19 changed files
with
386 additions
and
7 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,23 @@ | ||
<?php | ||
|
||
namespace App; | ||
|
||
use App\Model; | ||
|
||
class Certificate extends Model | ||
{ | ||
/** | ||
* Get the school record associated with the user. | ||
*/ | ||
public function school() | ||
{ | ||
return $this->belongsTo('App\School'); | ||
} | ||
/** | ||
* Get the student record associated with the user. | ||
*/ | ||
public function student() | ||
{ | ||
return $this->belongsTo('App\User','given_to', 'student_code'); | ||
} | ||
} |
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,93 @@ | ||
<?php | ||
|
||
namespace App\Http\Controllers; | ||
|
||
use App\Certificate; | ||
use Illuminate\Http\Request; | ||
|
||
class CertificateController extends Controller | ||
{ | ||
/** | ||
* Display a listing of the resource. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function index() | ||
{ | ||
$certificates = Certificate::where('given_to', \Auth::user()->student_code) | ||
->bySchool(\Auth::user()->school_id) | ||
->get(); | ||
return view('certificates.index',['certificates'=>$certificates]); | ||
} | ||
|
||
/** | ||
* Show the form for creating a new resource. | ||
* | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function create() | ||
{ | ||
$certificates = Certificate::with('student') | ||
->bySchool(\Auth::user()->school_id) | ||
->where('active',1)->get(); | ||
return view('certificates.create',['certificates'=>$certificates]); | ||
} | ||
|
||
/** | ||
* Store a newly created resource in storage. | ||
* | ||
* @param \Illuminate\Http\Request $request | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function store(Request $request) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Display the specified resource. | ||
* | ||
* @param \App\Certificate $certificate | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function show(Certificate $certificate) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Show the form for editing the specified resource. | ||
* | ||
* @param \App\Certificate $certificate | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function edit(Certificate $certificate) | ||
{ | ||
// | ||
} | ||
|
||
/** | ||
* Update the specified resource in storage. | ||
* | ||
* @param int $id | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function update($id) | ||
{ | ||
$tb = Certificate::find($id); | ||
$tb->active = 0; | ||
$tb->save(); | ||
return back()->with('status',__('File removed')); | ||
} | ||
|
||
/** | ||
* Remove the specified resource from storage. | ||
* | ||
* @param \App\Certificate $certificate | ||
* @return \Illuminate\Http\Response | ||
*/ | ||
public function destroy(Certificate $certificate) | ||
{ | ||
// | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
use App\User; | ||
use App\Certificate; | ||
use App\School; | ||
use Faker\Generator as Faker; | ||
|
||
$factory->define(Certificate::class, function (Faker $faker) { | ||
return [ | ||
'file_path' => $faker->url, | ||
'title' => $faker->sentences(1, true), | ||
'given_to' => $faker->randomElement(User::where('role', 'student')->pluck('student_code')->toArray()), | ||
'active' => $faker->randomElement([0, 1]), | ||
'school_id' => function() use ($faker) { | ||
if (School::count()) | ||
return $faker->randomElement(School::pluck('id')->toArray()); | ||
else return factory(School::class)->create()->id; | ||
}, | ||
'user_id' => function() use ($faker) { | ||
if (User::count()) | ||
return $faker->randomElement(User::pluck('id')->toArray()); | ||
else return factory(User::class)->create()->id; | ||
}, | ||
]; | ||
}); |
37 changes: 37 additions & 0 deletions
37
database/migrations/2020_07_24_201246_create_certificates_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,37 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
class CreateCertificatesTable extends Migration | ||
{ | ||
/** | ||
* Run the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function up() | ||
{ | ||
Schema::create('certificates', function (Blueprint $table) { | ||
$table->id(); | ||
$table->timestamps(); | ||
$table->string('file_path'); | ||
$table->string('title'); | ||
$table->integer('given_to'); | ||
$table->tinyInteger('active'); | ||
$table->integer('school_id')->unsigned(); | ||
$table->integer('user_id')->unsigned(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
* | ||
* @return void | ||
*/ | ||
public function down() | ||
{ | ||
Schema::dropIfExists('certificates'); | ||
} | ||
} |
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,16 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Seeder; | ||
|
||
class CertificateTableSeeder extends Seeder | ||
{ | ||
/** | ||
* Run the database seeds. | ||
* | ||
* @return void | ||
*/ | ||
public function run() | ||
{ | ||
factory(App\Certificate::class, 50)->create(); | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
@extends('layouts.app') | ||
|
||
@section('title', 'Give Certificate') | ||
@section('content') | ||
<div class="container-fluid"> | ||
<div class="row"> | ||
<div class="col-md-2" id="side-navbar"> | ||
@include('layouts.leftside-menubar') | ||
</div> | ||
<div class="col-md-10" id="main-container"> | ||
<div class="panel panel-default"> | ||
<div class="page-panel-title">Give Certificate</div> | ||
<div class="panel-body"> | ||
@if (session('status')) | ||
<div class="alert alert-success"> | ||
{{ session('status') }} | ||
</div> | ||
@endif | ||
@component('components.file-uploader',['upload_type'=>'certificate']) | ||
@endcomponent | ||
@component('components.uploaded-files-list',['files'=>$certificates,'upload_type'=>'certificate']) | ||
@endcomponent | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
@endsection |
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,26 @@ | ||
@extends('layouts.app') | ||
|
||
@section('title', 'My Certificates') | ||
@section('content') | ||
<div class="container-fluid"> | ||
<div class="row"> | ||
<div class="col-md-2" id="side-navbar"> | ||
@include('layouts.leftside-menubar') | ||
</div> | ||
<div class="col-md-10" id="main-container"> | ||
<div class="panel panel-default"> | ||
<div class="page-panel-title">My Certificates</div> | ||
<div class="panel-body"> | ||
@if (session('status')) | ||
<div class="alert alert-success"> | ||
{{ session('status') }} | ||
</div> | ||
@endif | ||
@component('components.certificate-list',['files'=>$certificates]) | ||
@endcomponent | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
@endsection |
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,22 @@ | ||
<div class="table-responsive"> | ||
<table class="table table-bordered table-data-div table-hover"> | ||
<thead> | ||
<tr> | ||
<th scope="col">#</th> | ||
<th scope="col">@lang('File Name')</th> | ||
<th scope="col">Received Date</th> | ||
</tr> | ||
</thead> | ||
<tbody> | ||
@isset($files) | ||
@foreach($files as $file) | ||
<tr> | ||
<td>{{($loop->index + 1)}}</td> | ||
<td><a href="{{url($file->file_path)}}" target="_blank">{{$file->title}}</a></td> | ||
<td>{{$file->created_at->format('M d Y')}}</td> | ||
</tr> | ||
@endforeach | ||
@endisset | ||
</tbody> | ||
</table> | ||
</div> |
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.