Ain

Ain

Member Since 3 Months Ago

Experience Points 1,520
Experience Level 1

3,480 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 0
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • Chatty Cathy Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

15 May
1 month ago

Ain left a reply on Bootswatch

@SNAPEY - i know right? ok thanks snapey

Ain started a new conversation Bootswatch

This is some random question,

but does Bootswatch consider as software?

23 Apr
2 months ago

Ain left a reply on My Add Group Member Button Not Fuctioning (javascript)

@FTIERSCH - How to I include jquery, and where?

Ain left a reply on My Add Group Member Button Not Fuctioning (javascript)

@MVD - i am very sorry mvd, my javascript knowledge is not that good. Can you show me how?

Ain left a reply on My Add Group Member Button Not Fuctioning

@FTIERSCH - This is my app.blade.php

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<html lang="{{ app()->getLocale() }}">
<head>
   <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
   <link  href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css" rel="stylesheet">
   <link rel="stylesheet" href="css/app.css">

  
   {{--Bootswatch:2--}}
   <!-- Latest compiled and minified CSS -->
   <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
   
<!-- Optional theme -->
   <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap-theme.min.css">
   
<!-- Latest compiled and minified JavaScript -->
   <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>

   <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootswatch/3.2.0/css/pulse/bootstrap.min.css">
  


   <!-- CSRF Token -->
   <meta name="csrf-token" content="{{ csrf_token() }}">

   <title>{{ config('dev.name','ICJS') }}</title>

   <!-- Scripts -->
   <script src="{{ asset('js/app.js') }}" defer></script>

   {{--<!-- Fonts -->--}}
   {{--<link rel="dns-prefetch" href="//fonts.gstatic.com">--}}
   {{--<link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet" type="text/css">--}}

   <!-- Styles -->
   {{--<link href="{{ asset('css/app.css') }}" rel="stylesheet">--}}
</head>


<body>
<div id="app">

   @include('include.navbar')

   <main class="py-4">
       @yield('content')
   </main>
</div>
</body>
</html>


@yield('script')


Ain started a new conversation My Add Group Member Button Not Fuctioning

"Add Group Member" button supposedly will display new row for user to enter data like this. https://imgur.com/a/pLJsoy8

But in this case, there is new roe when i clicked on it.

this is my blade : create.blade.php

@extends('layouts.app')

@section('content')

   <div class="container">
   <div class="row">
   <div class="col-md-11 col-md-offset-2">

   <div class="col-sm-9">
       <h1>Add Group</h1>

       {!! Form::open(['method' => 'POST', 'action' => ['[email protected]']]) !!}


       {!! Form::label('name', 'Name:') !!}
       {!! Form::text('name', null, ['class' => 'form-control', 'placeholder' => 'Group Name']) !!}

       {!! Form::label('product_name', 'Product Name:') !!}
       {!! Form::text('product_name', null, ['class' => 'form-control', 'placeholder' => 'Product Name']) !!}

       {!! Form::label('product_type', 'Product Type:') !!}
       {!! Form::text('product_type', null, ['class' => 'form-control', 'placeholder' => 'Product Type']) !!}

       {{--{!! Form::label('product_type', 'Product Type:') !!}--}}
       {{--{!! Form::select('product_type', ['' => '--- Choose Product Type ---'] + $pluck_products, null, ['class' => 'form-control', 'required']) !!}--}}


       <h3>Group Member</h3>

           <div class="container-fluid">
               {{--store data form in array for multiple group members--}}

               <table class="table table-bordered" id="dynamic_field">
                       <tr>
                           <td>
                               {!! Form::text('group_member[0][name]', null , ['class' => 'form-control', 'placeholder' => 'Name']) !!}
                           </td>
                           <td>
                               {!! Form::text('group_member[0][affiliation]', null, ['class' => 'form-control', 'placeholder' => 'Affiliation']) !!}
                           </td>
                           <td>
                               <button title='Add Member' type="button" id="add" class="btn btn-primary">Add Group Member</button>
                           </td>
                       </tr>
               </table>
           </div>

       <br/>
       {!! Form::submit('Create Group', ['class'=>'btn btn-primary btn-lg col-sm-12']) !!}
       {!! Form::close() !!}
   </div>

   </div>
   </div>
   </div>

@endsection

@section('script')
   <script type="text/javascript">
       // ------ Adding new row of input fields to create new group members
       var i=1;
       var j=1;

       $('#add').click(function(){

           // The limit of the author can be added.
           if(i < 5){

               i++; // adding the authors count to one if add button is clicked

               $('#dynamic_field')
                   .append('' +
                       '<tr id="row'+i+'" class="dynamic-added">' +
                       '<input name="group_member['+j+'][id]" type="hidden" class="form-control" id="id">' +
                       '<td>' +
                       '<input name="group_member['+j+'][name]" type="text" class="form-control " placeholder="Name" id="name" required>' +
                       '</td>' +
                       '<td>' +
                       '<input name="group_member['+j+'][affiliation]" type="text" class="form-control " placeholder="Affiliation" id="affiliation" required>' +
                       '</td>' +
                       '<td>' +
                       '<button title="Remove Field" type="button" name="remove" id="'+i+'" class="btn btn-danger btn_remove ">Remove Group Member</button>' +
                       '</td>' +
                       '</tr>'
                   );

               j++; // Author array[]
           }
           else {
               alert('Limit of group members reached!');
           }

       });

       // ------ Action to remove the added fields
       $(document).on('click', '.btn_remove', function(){
           var button_id = $(this).attr("id");
           $('#row'+button_id+'').remove();

           i--; // Count author minus if one column removed
       });
   </script>
@endsection
22 Apr
2 months ago

Ain left a reply on Login Interface Take A Long Time To Display

@FTIERSCH - I access my project using local host

Ain started a new conversation Login Interface Take A Long Time To Display

Why does after I click on login at welcome page, it takes too long to response which is to display the login page. I would like to know the cause and how to deal with it.

Anybody know why and how?

16 Apr
2 months ago

Ain started a new conversation Bootstrap 3.3.7

I'm currently using bootstrap 3.3.7, but I couldn't find the documentation in order to modify the navbar color for example, or maybe the table design in my project.

Did you guys know how to deal with this?

14 Apr
2 months ago

Ain left a reply on Registration Redirect

@BOBBYBOUWMANN - its working! thank you bobby :)

Ain left a reply on Registration Redirect

@BOBBYBOUWMANN - Is it possible to direct it back to the register.blade instead of index for admin?

Ain left a reply on Registration Redirect

@BOBBYBOUWMANN - I already try to change it, but it still login into that new register user account.

Ain left a reply on Count (involving Pivot Table)

@BOBBYBOUWMANN - is this use to count the admin? because if yes, I already done that part. And only judge has assigned booth.

Ain started a new conversation Registration Redirect

I move the register part under admin, which means only admin can do the registration (after login into system).

But the problem is, after i click the register button, it automatically login that particular user.

I want to redirect it back to the register blade which is under current admin that login.

What should I do?

RegisterController

<?php

namespace App\Http\Controllers\Auth;

use App\User;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Validator;
use Illuminate\Foundation\Auth\RegistersUsers;

class RegisterController extends Controller
{
   /*
   |--------------------------------------------------------------------------
   | Register Controller
   |--------------------------------------------------------------------------
   |
   | This controller handles the registration of new users as well as their
   | validation and creation. By default this controller uses a trait to
   | provide this functionality without requiring any additional code.
   |
   */

   use RegistersUsers;

   /**
    * Where to redirect users after registration.
    *
    * @var string
    */
   protected $redirectTo = '/home';

   /**
    * Create a new controller instance.
    *
    * @return void
    */
   public function __construct()
   {
       $this->middleware('auth');
   }

   /**
    * Get a validator for an incoming registration request.
    *
    * @param  array  $data
    * @return \Illuminate\Contracts\Validation\Validator
    */
   protected function validator(array $data)
   {
       return Validator::make($data, [
           'name' => 'required|string|max:255',
           'email' => 'required|string|email|max:255|unique:users',
           'password' => 'required|string|min:6|confirmed',
       ]);
   }

   /**
    * Create a new user instance after a valid registration.
    *
    * @param  array  $data
    * @return \App\User
    */
   protected function create(array $data)
   {
       return User::create([
           'name' => $data['name'],
           'email' => $data['email'],
           'password' => bcrypt($data['password']),
           'role_id' => $data['role_id'],
           'salutation' => $data['salutation'],
           'affiliation' => $data['affiliation'],
           'expertise_field' => $data['expertise_field'],
       ]);
   }
}

Ain left a reply on Count (involving Pivot Table)

I really need help from you guys. Hope that somebody willing to help me :)

Ain left a reply on Count (pivot Table)

@BOBBYBOUWMANN - Thank you for replying bobby. I try to understand the counting related models, but do not get it. Do you mind showing me how apply it to my project? Showing 1 example out of the 4 is already helpful for me.

Ain started a new conversation Count (pivot Table)

Im trying to count assigned judge, non assigned judge, assigned booth and non assigned booth. In database, there is a pivot table between user(judge) and booth, named booth_user. It contain user_id, booth_id and booth_user_id.

Each judge that already assigned to booth have other id which is booth_user_id. But the thing is, I dont know how to count the 4 mentioned above.

Controller

<?php

namespace App\Http\Controllers;

use App\Booth;
use App\BoothUser;
use App\Group;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class AdminController extends Controller
{
   public function index()
   {
       $admin = User::where('role_id','=','1')->get();
       $judge = User::where('role_id','=','2')->get();
       $group = Group::count();
       $booth = Booth::count();

       $assigned_booth = ;
       $non_assigned_booth = ;

       $assigned_judge = ;
       $non_assigned_judge = ;


       return view('staff.index', ['admin' => $admin, 'judge' => $judge, 'group' => $group, 'booth' => $booth]);

   }
}

Blade

@extends('layouts.app')

@section('content')

   <div class="container">
       <div class="row">
           <div class="col-md-8 col-md-offset-2">
               <div class="panel panel-default">
                   <div class="panel-heading">Admin Menu</div>

                   <div class="panel-body">

                      <h4>Group : {{$group}}</h4>  <br/>

                      <h4>Booth : {{$booth}}</h4> <br/>

                       <h4>Assigned Booth : </h4> <br/>

                       <h4>Non Assigned Booth : </h4> <br/>

                      <h4>Judge : {{ $judge->count() }}</h4> <br/>

                      <h4>Assigned Judge : </h4> <br/>

                      <h4>Non Assigned Judge : </h4> <br/>

                      <h4>Admin : {{ $admin->count() }}</h4> <br/>

                   </div>
               </div>
           </div>
       </div>
   </div>

@endsection

13 Apr
2 months ago

Ain left a reply on Dropdown Menu Does Not Use Css

@MUNAZZIL - Hi Munazzil. Do i have to add the script like this? But it still not working.

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
   <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
   <link  href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css" rel="stylesheet">
   <link rel="stylesheet" href="css/app.css">

   <link href="{{ mix('css/app.css') }}" rel="stylesheet" type="text/css">

   <meta charset="utf-8">
   <meta name="viewport" content="width=device-width, initial-scale=1">

   <!-- CSRF Token -->
   <meta name="csrf-token" content="{{ csrf_token() }}">

Ain left a reply on Dropdown Menu Does Not Use Css

@MAVERICKCHAN - Hey MaverickChan, I already delete it, but still the same.

11 Apr
2 months ago

Ain started a new conversation Dropdown Menu Does Not Use Css

This is my current drop down. https://imgur.com/a/YPXs1TS

This is my layouts->app.blade.php

<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
    <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
    <link  href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css" rel="stylesheet">
    <link rel="stylesheet" href="css/app.css">

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- CSRF Token -->
    <meta name="csrf-token" content="{{ csrf_token() }}">

    <title>{{ config('dev.name','ICJS') }}</title>

    <!-- Scripts -->
    <script src="{{ asset('js/app.js') }}" defer></script>

    <!-- Fonts -->
    <link rel="dns-prefetch" href="//fonts.gstatic.com">
    <link href="https://fonts.googleapis.com/css?family=Nunito" rel="stylesheet" type="text/css">

    <!-- Styles -->
    <link href="{{ asset('css/app.css') }}" rel="stylesheet">
</head>
<body>
<div id="app">

    @include('include.navbar')

    <main class="py-4">
        @yield('content')
    </main>
</div>
</body>
</html>

{{--<script src="js/app.js" charset="utf-8"></script>--}}

@yield('script')


10 Apr
2 months ago

Ain left a reply on Count In Controller

@FTIERSCH - Ahh I see, Thankyou ftiersch!

Ain started a new conversation Count In Controller

If we want a specific data to be count, we do like this

$judge = User::where('role_id','=','2')->get();

But what if we want to count how many record in database? Do we do it like this?

$group = Group::all()->get();

Ain left a reply on Returning Count To Blade

@STEREOH - I see, alright then. Thank you again! :)

Ain left a reply on Returning Count To Blade

@STEREOH - Hi stereoh! Thnakyou for replying. I already add in the coding like this

return view('staff.index', ['admin' => $admin]);

But it display the same error

Ain left a reply on How Do I Display The Value Of Count() Inside Blade View?

@ELO - hi elo, can you share how you share the variable when returning the view?

Ain started a new conversation Returning Count To Blade

Im trying to return count to blade, but there is an error. Undefined variable: admin (View: C:\xampp\htdocs\icjs\resources\views\staff\index.blade.php)

Blade

<h4>Admin : {{ $admin->count() }}</h4> <br/>

Controller

$admin = User::where('role_id','=','1')->get();

07 Apr
2 months ago

Ain left a reply on Undefined Variable Error

Its okay guys, already found the solution. It is because there is no data in database. I forgot that i do php artisan migrate:fresh earlier.

Ain started a new conversation Undefined Variable Error

I got Undefined variable: total_marks error

This is my blade

@extends('layouts.app')





@section('content')

    <h1>Report</h1>

    <div class="col-md-7">
        <table class="table table-bordered" >
            <thead>
            <tr>
                {{--<th>No.</th>--}}
                <th>Group Name</th>
                <th>Booth Number</th>
                <th>Judges</th>
                <th>Total Mark (Average)</th>

            </tr>
            </thead>
            <tbody>

                @foreach($booths as $booth)
                    <tr>
                        {{--Group Name--}}
                        @if($booth->group)
                            <td>{{$booth->group->name}}</td>
                        @endif

                        {{--Booth Number--}}
                        <td>{{$booth->booth_name}}</td>

                        {{--Judges--}}
                        @if(count($booth->judge) > 0)
                            <td>

                                @foreach($booth->judge as $judge)
                                    {{$judge->name}}
                                    <?php $total_marks = 0; ?>
                                    @foreach($judge->pivot->criteria_scale as $s)
                                        <?php
                                            $total_marks += $s->scale_id / 5 * $s->criteria->weightage;
                                        ?>
                                    @endforeach
                                    (Marks: {{$total_marks}})<br/>
                                @endforeach
                            </td>
                        @endif
                        {{--Total Mark--}}
                        <td>{{$total_marks/count($booth->judge)}}</td>
                    </tr>
                @endforeach
            </tbody>
        </table>
    </div>


@stop

It said that the errror is at

<?php
           $total_marks += $s->scale_id / 5 * $s->criteria->weightage;
 ?>

It works before this, but suddenly the error appear.

06 Apr
2 months ago

Ain left a reply on How To Add Confirmation Message Before Deleting

@JACKL - Oh my god, it works! Thank you JACKL for saving my life! Have a great day :)

Ain left a reply on How To Add Confirmation Message Before Deleting

@TRAY2 - I try, this is my blade:

 <div class="col-sm-6">
                <b>Judges List:</b><br/>
                    @foreach($booth->judge as $j)
                        {!! Form::open(['method' => 'POST', 'action' => ['[email protected]_judge']]) !!}
                            <input type="hidden" name="booth_id" value="{{$booth->id}}">
                            <input type="hidden" name="judge_id" value="{{$j->id}}">
                            <tr>
                                <td width="50%"> {{$j->name}} </td>

                                {{--<td width="50%"> {!! Form::submit('Unassigned Judge', ['class'=>'btn btn-danger']) !!} </td><br/>--}}
                                {{--<button title='Unassigned Judge' type="delete"  class="btn btn-danger">Unassigned Judge</button>--}}

                                <form class="delete"  method="POST" >
                                    <input type="hidden" name="_method" value="DELETE" >
{{--                                    {{ csrf_field() }}--}}
                                    <input type="submit" value="Unassigned Judge">
                                </form>
                                <script>
                                    $(".delete").on("submit", function(){
                                        return confirm("Are you sure?");
                                    });
                                </script>
                            </tr>
                        {!! Form::close() !!}
                    @endforeach

            </div>

But i get this error

https://imgur.com/a/Yw22fvU

05 Apr
2 months ago

Ain left a reply on Update From 5.5 To 5.6

@SNAPEY - Thank you for reply snapey. So I have to change from 5.4.0 to 5.6.0? Is it okay to jump from 4 to 6?

Oh, due to some reason, I need to upgrade it from 1 level to another. (5->6->7)

Ain started a new conversation How To Add Confirmation Message Before Deleting

I already google about this but couldn't understand on how to do it with my project. And i'm not good in javascript. Can anybody help me?

This is my controller

 public function unassigned_judge(Request $request){

        $judge_id = $request->input('judge_id');
        $judge = User::findOrFail($judge_id);
        $booth_id = $request->input('booth_id');
        $judge->booth()->detach($booth_id);


        return redirect()->back();
    }

This is my blade

<div class="col-sm-6">
                <b>Judges List:</b><br/>
                    @foreach($booth->judge as $j)
                        {!! Form::open(['method' => 'POST', 'action' => ['[email protected]_judge']]) !!}
                            <input type="hidden" name="booth_id" value="{{$booth->id}}">
                            <input type="hidden" name="judge_id" value="{{$j->id}}">
                            <tr>
                                <td width="50%"> {{$j->name}} </td>

                                {{--<td width="50%"> {!! Form::submit('Unassigned Judge', ['class'=>'btn btn-danger']) !!} </td><br/>--}}
                                <button title='Unassigned Judge' type="delete"  class="btn btn-danger">Unassigned Judge</button>
                            </tr>
                        {!! Form::close() !!}
                    @endforeach

            </div>

Ain started a new conversation Update From 5.5 To 5.6

I am currently trying to update my laravel from 5.5 to 5.6 but in composer.json i have this line

 "laravelcollective/html": "^5.4.0"

can I change it like this

 "laravelcollective/html": "^5.6.0"

or not? Or what should I do? change it to 5.5.0?

03 Apr
2 months ago

Ain left a reply on Type Error: Too Few Arguments To Function

@SERGIU17 - I see, thankyou Sergiu for helping me :)

Ain left a reply on Type Error: Too Few Arguments To Function

@SERGIU17 - i dont want to adjust the route, but if i remove $id in function, this line will be error at $id

$total_marks = KiraScore::getScoreByJudge($id);

Ain started a new conversation Type Error: Too Few Arguments To Function

Type error: Too few arguments to function App\Http\Controllers\ScoreController::report(), 0 passed and exactly 1 expected

This is my controller

public function report ($id)
    {
        // get all booth
        $booths = Booth::all();
        $total = 0;

        // iterate booth
        foreach($booths as $b){

            // get all judge evaluation score criteria, boleh guna judge kat booth model
            foreach($booths->judge as $judge){

                // calculate total mark for each evaluation form
                $total_marks = KiraScore::getScoreByJudge($id);

                // total marks of all of judge
                $total += $total_marks;

            }
            // assign value to each booth
            $booths->booth()->attach($total);
        }
}

This is my route

Route::get('/admin/report', '[email protected]')->name('admin.report');

Ain started a new conversation How To Do Sum In Laravel

Is this the correct way to do it?

$total = $total + $total_marks

And another question, what does this means

$total_marks += $criteria_mark;

Ain started a new conversation How To Display Report (please Help Me)

I am currently doing a system for judging process in innovation competition and I am new in laravel.

Judges(user) have many to many relationship with booth. This is my erd: https://imgur.com/a/bmqtakF

I am trying to do the report, but I seriously do not know how to total up all total marks obtain by each booth through the evaluation form. This is my current report view: https://imgur.com/a/p5RDVnX

This is the example of total mark (calculated in index function in controller) for that particular evaluation form which is for 1 booth (access evaluation form from judge account). https://imgur.com/a/QqNFJ7b

This is my controller.

<?php

namespace App\Http\Controllers;

use App\Booth;
use App\BoothUser;
use App\Group;
use App\Product;
use App\CriteriaScale;
use App\Criteria;
use App\Scale;
use App\User;
use Illuminate\Http\Request;

class ScoreController extends Controller
{
    /**
     * Display a listing of the resource.
     *
     * @param $id
     * @return \Illuminate\Http\Response
     */
    public function index($id)
    {
        $criteria = Criteria::all();
        $scale = Scale::all();
        $judge_booth_id = $id;
        $score = CriteriaScale::where('booth_user_id', $id)->get();
        $total_marks = 0;
        $booth = Booth::findOrFail($id);

        if(count($score) > 0){
            // Retrieve criteria & score for a the evaluation marks
            foreach($score as $s)
            {
                $weightage = Criteria::findOrFail($s->criteria_id)->weightage;

                // Score Given / Scale * weightage
                $criteria_mark = $s->scale_id / 5 * $weightage;

                $total_marks += $criteria_mark;
            }
        }
//        $this->report($total_marks);

        return view('judge.evaluation_form', compact( 'score','criteria','scale', 'judge_booth_id', 'total_marks', 'booth'));
    }

    /**
     * Show the form for creating a new resource.
     *
     * @return \Illuminate\Http\Response
     */
    public function create()
    {
        //
    }

    /**
     * Store a newly created resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return \Illuminate\Http\Response
     */
    public function store(Request $request)
    {

        $scale = $request->input('scale');
        $booth_user_id = $request->input('judge_booth_id');
//        return $request->all();

        foreach($scale as $key=>$value){
            // scale_id == value
            // criteria_id == key
            // booth_user_id = judge_booth_id

            // Check if score exists or not
            $score_exist = CriteriaScale::where('booth_user_id', $booth_user_id)->where('criteria_id', $key)->get();

            if(count($score_exist) > 0)
            {
                // Read by criteria_id
//                $score_exist['scale_id'] = $value;
//                $score_exist->save();
                $score_exist->first()->update(['scale_id' => $value]);

            }
            else
            {
                // Create if not exist
                CriteriaScale::create(
                    [
                        'scale_id'=>$value,
                        'criteria_id'=>$key,
                        'booth_user_id'=>$booth_user_id
                    ]
                );
            }


        }

        return redirect()->back();
    }

    /**
     * Display the specified resource.
     *
     * @param  \App\Score  $score
     * @return \Illuminate\Http\Response
     */

    public function show(Score $score)
    {
        //
    }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  \App\Score  $score
     * @return \Illuminate\Http\Response
     */
    public function edit(Score $score)
    {
        //
    }

    /**
     * Update the specified resource in storage.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \App\Score  $score
     * @return \Illuminate\Http\Response
     */
    public function update(Request $request, Score $score)
    {
        //
    }

    /**
     * Remove the specified resource from storage.
     *
     * @param  \App\Score  $score
     * @return \Illuminate\Http\Response
     */
    public function destroy(Score $score)
    {
        //
    }

    public function report ()
    {
        $booths = Booth::all();


        return view('admin.report', compact('booths'));
    }

}

This is my blade

@extends('layouts.app')





@section('content')

    <h1>Report</h1>

    <div class="col-md-4">
        <table class="table table-bordered" >
            <thead>
            <tr>
                {{--<th>No.</th>--}}
                <th>Group Name</th>
                <th>Booth Number</th>
                <th>Judges</th>
                <th>Total Mark</th>

            </tr>
            </thead>
            <tbody>

                @foreach($booths as $booth)
                    <tr>
                        {{--Group Name--}}
                        @if($booth->group)
                            <td>{{$booth->group->name}}</td>
                        @endif

                        {{--Booth Number--}}
                        <td>{{$booth->booth_name}}</td>

                        {{--Judges--}}
                        @if(count($booth->judge) > 0)
                            <td>
                                @foreach($booth->judge as $judge)
                                    {{$judge->name}}<br/>
                                @endforeach
                            </td>
                        @endif

                        {{--Total Mark--}}
                        {{--judge(user) <--many to many--> booth--}}
                        {{--Total up all 'total mark' judges give during evaluation (for each booth)--}}
                        

                    </tr>
                @endforeach

            </tbody>
        </table>
    </div>


@stop
31 Mar
2 months ago

Ain left a reply on Data Stored '2' Instead Of 'Agriculture' In Db

@CRONIX - ohh sorry. i have 2 tables.

first is products which I want the data to be stored as 'Agriculture'

https://imgur.com/a/xOTt6j3

second table is product_types where i use this table to display the drop list

https://imgur.com/a/pTFhQCc

Ain started a new conversation Data Stored '2' Instead Of 'Agriculture' In Db

This is my store function in controller

public function store(Request $request)
    {
        //return $request->input('name');
//        return $request->all();

        $group_name = $request->input('name');
        $product_name = $request->input('product_name');
        $product_type = $request->input('product_type');
        $group_members = $request->input('group_member');

        //kena ikut turutan

        $product = Product::create(
            [
                'name' => $product_name,
                'type' => $product_type
            ]
        );


        $group = Group::create(
            [
                'name' => $group_name,
                'product_id' => $product->id
            ]
        );


        foreach($group_members as $group_member){
            $group_member['group_id'] = $group->id;
            GroupMember::create($group_member);
        }


        return redirect()->back();

    }

This is my blade

{!! Form::label('product_type', 'Product Type:') !!}
{!! Form::select('product_type', ['' => '--- Choose Product Type ---'] + $pluck_products, null, ['class' => 'form-control', 'required']) !!}

This is my drop list data in database:

id=1 type=Computing id=2 type=Agriculture

30 Mar
2 months ago

Ain left a reply on Set Up Environment

@TYKUS - thank youu tykus!

Ain started a new conversation Set Up Environment

I formatted my laptop because the internal hard disk need to be change. Do I have to install git and composer back?

20 Mar
3 months ago

Ain left a reply on How To Add Some Lines In Table

@JLRDW - Already got it! Thankss :))

Ain left a reply on How To Move The Radio Button To The Left?

@CRONIX - I already get it, thank you for your help and time Cronix :)

Ain left a reply on How To Move The Radio Button To The Left?

@JLRDW - I already get it by using if else, thank you for helping me! Thank you for your time also :)

Ain left a reply on How To Move The Radio Button To The Left?

@CRONIX - I did, and it turn out like this https://imgur.com/a/juyH833

I couldn't manage to do the " JUDGING CRITERIA - PRESENTATIONS" because it is in foreach loop.

And become like this https://imgur.com/a/Nxd7lqb

Ain left a reply on How To Move The Radio Button To The Left?

@CRONIX - But my criteria coding is in foreach loop. Can you maybe help me again to solve this? Thank you in advance :)

Ain started a new conversation How To Add Some Lines In Table

I am trying to do it like this https://imgur.com/a/RgbHfHJ

But I dont know how to insert the " JUDGING CRITERIA - INNOVATION PROJECT / PROTOTYPE " and " JUDGING CRITERIA - PRESENTATIONS" lines

My current display https://imgur.com/a/tD4cHvI

@extends('layouts.app')

@section('content')


   <div class="col-sm-10 col-lg-push-1">
       <h1>Evaluation Form</h1>

            {{--<td>Product Name</td>--}}
             {{--<td>:</td>--}}
            {{--<td>{{$booths->booth->group->product->name}}</td>--}}


       <div class="form-group col-lg-10">
           <table class="table-bordered">
               <tr>
                   <td>Criteria (Circle one rating per criteria evaluated)</td>
                   <td>Does Not Achieve Expectations (Major Development Need) </td>
                   <td>Partially Achieves Expectations (Development Need)</td>
                   <td>Achieves Expectations (Neither Strength Nor Development Need)</td>
                   <td>Exceeds Expectations (Strength)</td>
                   <td>Greatly Exceeds Expectations (Major Strength)</td>
               </tr>

               @foreach($criteria as $c)
                   <tr>
                       <td>
                           {{$c->name}}
                       </td>


                       @foreach($scale as $s)
                           <td>
                               {{$s->name}}
                               <br>
                               {{ Form::radio('scale['.$c->id.']', $s->name) }}
                           </td>
                       @endforeach

                   </tr>
               @endforeach

           </table>
       </div>

   </div>

@endsection