Online Quiz Platform in laravel | Online exam system | Online quiz system in laravel | part - 1

 

 


 Controller

<?php

namespace App\Http\Controllers\Exam;

use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Model\Quizes;
use App\Model\Questions;
class QuizController extends Controller
{
    public function __construct()
    {
      
        $this->middleware('manager');
    }
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function index()
    {
          $quizes=Quizes::orderBy('id','desc')->paginate(50);
        return view('Exam.quiz.view',compact('quizes'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        $quizes=Quizes::orderBy('id','desc')->paginate(50);
        return view('Exam.quiz.create',compact('quizes'));
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {
         $this->validate($request,[
        'quiz_name'=>'required|unique:quizes',


       ]);
       $data=$request->all();
       Quizes::create($data);
       
       return redirect()->back()->with('success','Data add successfully');

    }

    /**
     * Display the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function show($id)
    {
        $data=Quizes::find($id);
        $questions=Questions::where('quizes_id',$id)->get();
         return view('Exam.quiz.details',compact('data','questions'));
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
        $data=Quizes::find($id);
         $quizes=Quizes::orderBy('id','desc')->get();
         return view('Exam.quiz.edit',compact('quizes','data'));
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, $id)
    {
         $this->validate($request,[
        'quiz_name'=>'required',
        'quiz_time'=>'required',
       ]);
        $data=Quizes::find($id);
        $new_data=$request->all();
        $data->update($new_data);
        return redirect()->back()->with('success','Data update successfully');  

    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */

     public function status($id)
    {
        $data=Quizes::find($id);
        if($data->status=="1"){
            $data->status=0;
        }else{
        $data->status=1;
        }
        $data->save();

    }
    public function AddQuestion($id)
    {
        $quiz=Quizes::all();
        $quizId=Quizes::find($id);
        return view('Exam.question.add_question',compact('quiz','quizId'));

    }
    
    public function destroy($id)
    {
        //
    }
}
 

Model

 

<?php

namespace App\Model;

use Illuminate\Database\Eloquent\Model;

class Quizes extends Model
{
    protected $fillable=['categories_id','catelogs_id','quiz_name','description','quiz_time','quiz_date','status','number_of_question'];
    public function questions()
    {
        return $this->hasMany(Questions::class);
    }
    public function result()
    {
        return $this->hasOne(Results::class);
    }
     public function results()
    {
        return $this->hasMany(Results::class);
    }
    public function categories()
    {
        return $this->belongsTo('App\Categories');
    }
     public function catelogs()
    {
        return $this->belongsTo('App\Catelogs');
    }
}
 

Migration

$table->string('quiz_name')->nullable();
            $table->string('description')->nullable();
            $table->string('quiz_date')->nullable();
            $table->string('quiz_time')->nullable();
            $table->string('number_of_question')->nullable();
            $table->string('status')->nullable();


Resource /Views

Exam/create.blade.php

 
@extends('layouts.admin.master')
@section('title','Quiz add')
@section('content')

<div class="page-header">
<h1>
Quiz  Add
<small>
<i class="ace-icon fa fa-angle-double-right"></i>
Quiz for front page </small>&nbsp;<a href="/quizes">Quiz  View</a>
</h1>
</div><!-- /.page-header -->
<div class="row">
<div class="col-xs-12">
<!-- PAGE CONTENT BEGINS -->
 @include('admin.messages.message')

<form class="form-horizontal" role="form" action="/quizes" method="POST" enctype="multipart/form-data">
    {{csrf_field()}}
<div class="space-4"></div>
 
 
<div class="space-4"></div>
<div class="form-group">
    <label class="col-sm-3 control-label no-padding-right" for="form-field-2"> Quiz Name </label>
    <div class="col-sm-9">
         
     <input type="text" id="form-field-2" placeholder="Quize Name" class="col-xs-10 col-sm-5" name="quiz_name" required="" >
         
    </div>
</div>
<div class="form-group">
    <label class="col-sm-3 control-label no-padding-right" for="form-field-2">Description</label>
    <div class="col-sm-9">
        <input type="text" id="form-field-2" placeholder="Descriotion" class="col-xs-10 col-sm-5" name="description" required="" />
       
    </div>
</div>
<div class="form-group">
    <label class="col-sm-3 control-label no-padding-right" for="form-field-2">Quiz Date</label>
    <div class="col-sm-9">
        <input type="date" id="form-field-2" placeholder="quiz date" class="col-xs-10 col-sm-5" name="quiz_date"   />
       
    </div>
</div>
<div class="form-group">
    <label class="col-sm-3 control-label no-padding-right" for="form-field-2">Quiz Time</label>
    <div class="col-sm-9">
        <input type="text" id="form-field-2" placeholder="00:00"  pattern="[0-9]{2}:[0-9]{2}" class="col-xs-10 col-sm-5" name="quiz_time" required="" title="example 01:00 " />
        <span> exm: 00:00</span>
    </div>
</div>
<div class="form-group">
    <label class="col-sm-3 control-label no-padding-right" for="form-field-2">Number Of Question View for User</label>
    <div class="col-sm-9">
        <input type="text" id="form-field-2" placeholder="How many question view for this quiz " class="col-xs-10 col-sm-5" name="number_of_question" required="" />
       
    </div>
</div>
<div class="space-4"></div>
<div class="clearfix form-actions">
    <div class="col-md-offset-3 col-md-9">
        <button class="btn btn-info" type="submit">
            <i class="ace-icon fa fa-check bigger-110"></i>
            Submit
        </button>

        &nbsp; &nbsp; &nbsp;
        <button class="btn" type="reset">
            <i class="ace-icon fa fa-undo bigger-110"></i>
            Reset
        </button>
    </div>
</div>

<div class="hr hr-24"></div>

 
</form>

 <!-- PAGE CONTENT ENDS -->
</div><!-- /.col -->
</div>


<div class="col-md-12">
    {{$quizes->links()}}
    <table class="table table-bordered" id="datatables">
       <thead>
           <tr>
               <th>Sl</th>
               <th>Quiz Name</th>
               <th>Description</th>
               <th>Date</th>
               <th>Time</th>
               <th> Total Qus</th>
               <th>Num of Exam Qus</th>
               <th>Status</th>
               <th>Add Question</th>
               <th>Details</th>
               <th>Edit</th>
               <th>Delete</th>
           </tr>
       </thead>
       <tbody>
           @foreach($quizes as $key=>$data)
           <tr>
               <td>{{++$key}} </td>
               <td>{{$data->quiz_name}} </td>
               <td>{{$data->description}} </td>
               <td>{{$data->quiz_date}} </td>
               <td>{{$data->quiz_time}} </td>
               <td>{{$data->questions->count()}}</td>
               <td>{{$data->number_of_question}} </td>
               <td><input type="checkbox" name="status" class="quiz-status" data_id="{{$data->id}}" {{$data->status=='1'?'checked':''}}> </td>

               <td><a href="/quize/addquestion/{{$data->id}}">Add Question</a></td>
               <td><a href="/quizes/{{$data->id}}">Details</a></td>
               <td><a href="/quizes/{{$data->id}}/edit">Edit</a></td>
               <td>{{Form::open(['url'=>'/quizes/'.$data->id,'method'=>'Delete'])}}
                <button type="submit" class="btn btn-danger btn-sm" onclick="return confirm('Are you sure delete this?')">Delete</button>
              {{Form::close()}}</td>
           </tr>
           @endforeach
       </tbody>
    </table>
</div>


@endsection

@section('js')

<script type="text/javascript">
 
    $(document).on('click','.quiz-status',function(){
     var id=$(this).attr('data_id');
   var url=("{!!url('/')!!}");
   
     $.get(url+'/quiz_status/'+id,function(fb){
         alert('Staus Successfully changed');
     });
    });
</script>
@endsection
@section('script')


            <script type="text/javascript">
                
                $('#category').on('change',function(e){
                    console.log(e);

                    var categories_id= e.target.value;

                    $.get('/json-catelogs?categories_id=' + categories_id,function(data){
                        console.log(data);

                    $('#catelog').empty();
          $('#catelog').append('<option value="" disable="true" selected="true">Select a Catelog</option>');

          $.each(data, function(index, districtsObj){
            $('#catelog').append('<option value="'+ districtsObj.id +'">'+ districtsObj.catelog +'</option>');
          });
         
                    });
                });
            </script>

<script src="http://netdna.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $('#summernote').summernote({
            height:'200px',
            placeholder:'Description',
            toolbar: [
    ['style', ['fontname','bold', 'italic', 'underline', 'clear']],
    ['font', ['strikethrough', 'superscript', 'subscript']],
    ['fontsize', ['fontsize']],
    ['color', ['color']],
    ['para', ['ul', 'ol', 'paragraph']],
    ['height', ['height']],
    ['table', ['table']],
            ['insert', ['link', 'picture', 'video', 'hr', 'readmore']],
            ['genixcms', ['elfinder']],
            ['view', ['fullscreen', 'codeview']],
  ],
         onImageUpload: function(files, editor, welEditable) {
            sendFile(files[0],editor,welEditable);
        }     
        });
    });
</script>
<script type="text/javascript">
function previewImage(event) {
var output = document.getElementById('output');
output.src = URL.createObjectURL(event.target.files[0]);
};
</script>
@endsection

view.blade.php

@extends('layouts.admin.master')
@section('title','Quiz view')
@section('content')

<div class="page-header">
<h1>
Quiz  Add
<small>
<i class="ace-icon fa fa-angle-double-right"></i>
Quiz for front page </small>&nbsp;<a href="/quizes/create">Add New Quiz </a>
</h1>
</div><!-- /.page-header -->
<div class="row">
<div class="col-xs-12">
<!-- PAGE CONTENT BEGINS -->
 @include('admin.messages.message')

 

 <!-- PAGE CONTENT ENDS -->
</div><!-- /.col -->
</div>

<div class="col-md-12">
    {{$quizes->links()}}
    <table class="table table-bordered" id="datatables">
       <thead>
           <tr>
               <th>Sl</th>
               <th>Quiz Name</th>
               <th>Description</th>
               <th>Date</th>
               <th>Time</th>
               <th>Total Qus</th>
               <th>Num of Exam Qus</th>
          <th>Status</th>
          <th>P.No</th>
               <th>Details</th>
               <th>Edit</th>
               <th>Delete</th>
           </tr>
       </thead>
       <tbody>
           @foreach($quizes as $key=>$data)
           <tr>
               <td>{{++$key}} </td>
               <td>{{$data->quiz_name}} </td>
               <td>{{$data->description}} </td>
               <td>{{$data->quiz_date}} </td>
               <td>{{$data->quiz_time}} </td>
                          <td>{{$data->questions->count()}}</td>
               <td>{{$data->number_of_question}} </td>
               <td><input type="checkbox" name="status" class="quiz-status" data_id="{{$data->id}}" {{$data->status=='1'?'checked':''}}> </td>
              <td>{{$data->results->count()}}</td>
          <td><a href="/quizes/{{$data->id}}">Details</a></td>
               <td><a href="/quizes/{{$data->id}}/edit">Edit</a></td>
               <td>{{Form::open(['url'=>'/quizes/'.$data->id,'method'=>'Delete'])}}
                <button type="submit" class="btn btn-danger btn-sm" onclick="return confirm('Are you sure delete this?')">Delete</button>
              {{Form::close()}}</td>
           </tr>
           @endforeach
       </tbody>
    </table>
</div>


@endsection

@section('js')

<script type="text/javascript">
 
    $(document).on('click','.quiz-status',function(){
     var id=$(this).attr('data_id');
   var url=("{!!url('/')!!}");
   
     $.get(url+'/quiz_status/'+id,function(fb){
         alert('Staus Successfully changed');
     });
    });
</script>
@endsection

update.blade.php


@extends('layouts.admin.master')
@section('title','Quiz Update')
@section('content')

<div class="page-header">
<h1>
Quiz  Update
<small>
<i class="ace-icon fa fa-angle-double-right"></i>
Quiz for front page </small>&nbsp;<a href="/quizes/create"> Add new Quiz </a>
</h1>
</div><!-- /.page-header -->
<div class="row">
<div class="col-xs-12">
<!-- PAGE CONTENT BEGINS -->
 @include('admin.messages.message')

 
     {{Form::open(['url'=>'/quizes/'.$data->id ,'method'=>'PATCH','class'=>'form-horizontal'])}}
<div class="space-4"></div>
 
<div class="space-4"></div>
 
<div class="space-4"></div>
<div class="form-group">
    <label class="col-sm-3 control-label no-padding-right" for="form-field-2"> Quiz Name </label>
    <div class="col-sm-9">
         
     <input type="text" id="form-field-2" placeholder="Quize Name" class="col-xs-10 col-sm-5" name="quiz_name" required="" value="{{$data->quiz_name}}" >
         
    </div>
</div>
<div class="form-group">
    <label class="col-sm-3 control-label no-padding-right" for="form-field-2">Description</label>
    <div class="col-sm-9">
        <input type="text" id="form-field-2" placeholder="Descriotion" class="col-xs-10 col-sm-5" name="description" required="" value="{{$data->description}}" />
       
    </div>
</div>
<div class="form-group">
    <label class="col-sm-3 control-label no-padding-right" for="form-field-2">Quiz Date</label>
    <div class="col-sm-9">
        <input type="date" id="form-field-2" placeholder="quiz date" class="col-xs-10 col-sm-5" name="quiz_date" value="{{$data->quiz_date}}"  />
       
    </div>
</div>
<div class="form-group">
    <label class="col-sm-3 control-label no-padding-right" for="form-field-2">Quiz Time</label>
    <div class="col-sm-9">
        <input type="text" id="form-field-2" placeholder="00:00"  pattern="[0-9]{2}:[0-9]{2}" class="col-xs-10 col-sm-5" name="quiz_time" required="" value="{{$data->quiz_time}}" title="example 01:00 " />
        <span> exm: 00:00</span>
    </div>
</div>
<div class="form-group">
    <label class="col-sm-3 control-label no-padding-right" for="form-field-2">Number Of Question View for User</label>
    <div class="col-sm-9">
        <input type="text" id="form-field-2" placeholder="How many question view for this quiz " class="col-xs-10 col-sm-5" name="number_of_question" required="" value="{{$data->number_of_question}}" />
       
    </div>
</div>
<div class="space-4"></div>
<div class="clearfix form-actions">
    <div class="col-md-offset-3 col-md-9">
        <button class="btn btn-info" type="submit">
            <i class="ace-icon fa fa-check bigger-110"></i>
            Update
        </button>

        &nbsp; &nbsp; &nbsp;
        <button class="btn" type="reset">
            <i class="ace-icon fa fa-undo bigger-110"></i>
            Reset
        </button>
    </div>
</div>

<div class="hr hr-24"></div>

 
{{Form::close()}}

 <!-- PAGE CONTENT ENDS -->
</div><!-- /.col -->
</div>

<div class="col-md-12">
    <table class="table table-bordered">
       <thead>
           <tr>
               <th>Sl</th>
               <th>Quiz Name</th>
               <th>Description</th>
               <th>Date</th>
               <th>Time</th>
               <th>Total Qus</th>
               <th>Num of Exam Qus</th>
               <th>Edit</th>
               <th>Delete</th>
           </tr>
       </thead>
       <tbody>
           @foreach($quizes as $key=>$quz)
           <tr>
               <td>{{++$key}} </td>
               <td>{{$quz->quiz_name}} </td>
               <td>{{$quz->description}} </td>
               <td>{{$quz->quiz_date}} </td>
               <td>{{$quz->quiz_time}} </td>
                   <td>{{$quz->questions->count()}}</td>
               <td>{{$quz->number_of_question}} </td>
               <td><a href="/quizes/{{$quz->id}}/edit">Edit</a></td>
               <td>{{Form::open(['url'=>'/quizes/'.$quz->id,'method'=>'Delete'])}}
                <button type="submit" class="btn btn-danger btn-sm" onclick="return confirm('Are you sure delete this?')">Delete</button>
              {{Form::close()}}</td>
           </tr>
           @endforeach
       </tbody>
    </table>
</div>
@endsection
@section('script')


            <script type="text/javascript">
                
                $('#category').on('change',function(e){
                    console.log(e);

                    var categories_id= e.target.value;

                    $.get('/json-catelogs?categories_id=' + categories_id,function(data){
                        console.log(data);

                    $('#catelog').empty();
          $('#catelog').append('<option value="" disable="true" selected="true">Select a Catelog</option>');

          $.each(data, function(index, districtsObj){
            $('#catelog').append('<option value="'+ districtsObj.id +'">'+ districtsObj.catelog +'</option>');
          });
         
                    });
                });
            </script>

<script src="http://netdna.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        $('#summernote').summernote({
            height:'200px',
            placeholder:'Description',
            toolbar: [
    ['style', ['fontname','bold', 'italic', 'underline', 'clear']],
    ['font', ['strikethrough', 'superscript', 'subscript']],
    ['fontsize', ['fontsize']],
    ['color', ['color']],
    ['para', ['ul', 'ol', 'paragraph']],
    ['height', ['height']],
    ['table', ['table']],
            ['insert', ['link', 'picture', 'video', 'hr', 'readmore']],
            ['genixcms', ['elfinder']],
            ['view', ['fullscreen', 'codeview']],
  ],
         onImageUpload: function(files, editor, welEditable) {
            sendFile(files[0],editor,welEditable);
        }     
        });
    });
</script>
<script type="text/javascript">
function previewImage(event) {
var output = document.getElementById('output');
output.src = URL.createObjectURL(event.target.files[0]);
};
</script>
@endsection

No comments

Powered by Blogger.