irankhosravi

irankhosravi

Member Since 10 Months Ago

Experience Points 7,420
Experience
Level
Lessons Completed 1
Lessons
Completed
Best Reply Awards 0
Best Answer
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.

10 Nov
6 days ago

irankhosravi left a reply on Update Approved Not Working

What do I do now?

irankhosravi started a new conversation Update Approved Not Working

When a user click on approved button, open a modal bootstrap. in modal has a select option, that select a user inspector . but it is not saving in database. I guess it has something to do with that fact that im trying to update an entry on the same page? Here is my Code:

After click on approved button

Approved

it be must approved = 1 and inspector user = 4

My blade

@extends('Admin.master')

@section('style')
    <link href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.css">
@endsection

@section('content')

    <div class="col-md-10">
        <div class="panel panel-default">
            <div class="panel-heading main-color-bg">
                <h3 class="panel-title">List of Requisitions</h3>
            </div>
        </div>
        <div class="panel panel-default">
            <div class="panel-body">
                <div class="table-responsive">
                    <table class="table">
                        <thead>
                        <tr>
                            <th>School Name</th>
                            <th>Requisition Code</th>
                            <th>Activity</th>
                            <th>Telephone</th>
                            <th>Requisition Type</th>
                            <th>Requisition Status</th>
                            <th>Display Details</th>
                        </tr>
                        </thead>
                        <tbody>
                        @forelse ($requisitions as $requisition)
                            @forelse($requisition->activities as $activity)
                                <tr>
                                    <td>{{ $requisition->schools->school_name }}</td>
                                    <td class="translate">{{ $requisition->id  }}</td>
                                    <td>{{ $activity->group->group_name  }}</td>
                                    <td>{{ $requisition->schools->type  }}</td>
                                    <td class="translate">{{ $requisition->schools->phone  }}</td>
                                    <td>{{ $requisition->schools->type }}</td>
                                    <td>
                                        <div class="btn-group btn-group-xs">
                                            <a  class="btn btn-success btn-xs" data-toggle="modal" data-target="#requisition">Approved</a>
                                            <form class="btn-group" action="{{ route('requisitions.unapproved', ['id' => $requisition->id]) }}" method="post">
                                                {{ method_field('PATCH') }}
                                                {{ csrf_field() }}
                                                <button type="submit" class="btn btn-danger btn-xs">Disapproval</button>
                                            </form>
                                        </div>
                                    </td>
                                    @empty
                                        Please go to back
                                    @endforelse
                                @empty
                                Please go to back
                            @endforelse
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="requisition" tabindex="-1" role="dialog">
        <div class="modal-dialog modal-sm" role="document">
            <div class="modal-content">
                <form  action="{{ route('requisitions.update', ['id' => $requisition->id]) }}" method="post">
                    {{ method_field('PATCH') }}
                    {{ csrf_field() }}
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title">List of inspection</h4>
                    </div>
                    <div class="modal-body">
                        <select class="form-control" name="inspector_user_id">
                            @foreach($users as $user)
                                <option value="{{ $user->id }}">{{ $user->first_name }} {{ $user->last_name }}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class="modal-footer">
                        <button type="submit" class="btn btn-primary">Save</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

@endsection

@section('script')
    <script src="https://unpkg.com/[email protected]/dist/sweetalert2.all.js"></script>
@endsection

Controller

public function update(Request $request, $requisition)
{
    $approved = Requisition::findOrFail($requisition);
    $approved->approved = 1;
    $approved->inspector_user_id = $request->input('inspector_user_id');
    $approved->save();
    alert()->success('It done', 'OK')->persistent('OK');
    return redirect()->back();
}

public function unapproved(Request $request, $id)
{
    $unApproved = Requisition::findOrFail($id);
    $unApproved->approved = 0;
    $unApproved->save();
    alert()->success('It done', 'Cancel')->persistent('OK');
    return redirect()->back();
}

My model

protected $fillable = [
    'status',
    'inspector_user_id'
];

web.php

Route::resource('requisitions', 'RequisitionController');
09 Nov
1 week ago

irankhosravi left a reply on My Approved Not Working

I apologize to all of you and I deleted my post

irankhosravi left a reply on My Approved Not Working

$r->save(); => true

If you can help me please help me why you waste time ???

irankhosravi left a reply on My Approved Not Working

I see this error.

php fatal error: call to undefined function save() in psy shell code on line 1

What's the problem?

irankhosravi left a reply on My Approved Not Working

It display this message again:

array:9 [▼
  "id" => 1
  "school_id" => 1
  "user_id" => 1
  "inspector_user_id" => null
  "type" => 1
  "status" => 1
  "approved" => 1
  "created_at" => "2018-11-08 20:35:03"
  "updated_at" => "2018-11-10 00:20:14"
]

irankhosravi left a reply on My Approved Not Working

When I click on id 2 I see this message

array:9 [▼
  "id" => 1
  "school_id" => 1
  "user_id" => 1
  "inspector_user_id" => null
  "type" => 1
  "status" => 1
  "approved" => 1
  "created_at" => "2018-11-08 20:35:03"
  "updated_at" => "2018-11-09 22:13:12"
]

irankhosravi left a reply on My Approved Not Working

nothing happened in database

irankhosravi left a reply on My Approved Not Working

Do not answer?

irankhosravi left a reply on My Approved Not Working

After click on approved button

https://screenshots.firefox.com/gQVbuVnfE635gq8Z/localhost

it be must approved = 1 and inspector user = 4

irankhosravi left a reply on My Approved Not Working

I see this

"1"

array:3 [▼
  "_method" => "PATCH"
  "_token" => "a2a5AbxyvlBPRETYYuq3yHO6Xi31ZDZxx3ddDxy4"
  "inspector_user_id" => "4"
]

irankhosravi started a new conversation My Approved Not Working

When a user click on approved button, open a modal bootstrap. in modal has a select option, that select a user inspector . but it is not saving in database.

My blade

@extends('Admin.master')

@section('style')
    <link href="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/1.1.3/sweetalert.css">
@endsection

@section('content')

    <div class="col-md-10">
        <div class="panel panel-default">
            <div class="panel-heading main-color-bg">
                <h3 class="panel-title">List of Requisitions</h3>
            </div>
        </div>
        <div class="panel panel-default">
            <div class="panel-body">
                <div class="table-responsive">
                    <table class="table">
                        <thead>
                        <tr>
                            <th>School Name</th>
                            <th>Requisition Code</th>
                            <th>Activity</th>
                            <th>Telephone</th>
                            <th>Requisition Type</th>
                            <th>Requisition Status</th>
                            <th>Display Details</th>
                        </tr>
                        </thead>
                        <tbody>
                        @forelse ($requisitions as $requisition)
                            @forelse($requisition->activities as $activity)
                                <tr>
                                    <td>{{ $requisition->schools->school_name }}</td>
                                    <td class="translate">{{ $requisition->id  }}</td>
                                    <td>{{ $activity->group->group_name  }}</td>
                                    <td>{{ $requisition->schools->type  }}</td>
                                    <td class="translate">{{ $requisition->schools->phone  }}</td>
                                    <td>{{ $requisition->schools->type }}</td>
                                    <td>
                                        <div class="btn-group btn-group-xs">
                                            <a  class="btn btn-success btn-xs" data-toggle="modal" data-target="#requisition">Approved</a>
                                            <form class="btn-group" action="{{ route('requisitions.unapproved', ['id' => $requisition->id]) }}" method="post">
                                                {{ method_field('PATCH') }}
                                                {{ csrf_field() }}
                                                <button type="submit" class="btn btn-danger btn-xs">Disapproval</button>
                                            </form>
                                        </div>
                                    </td>
                                    @empty
                                        Please go to back
                                    @endforelse
                                @empty
                                Please go to back
                            @endforelse
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="requisition" tabindex="-1" role="dialog">
        <div class="modal-dialog modal-sm" role="document">
            <div class="modal-content">
                <form  action="{{ route('requisitions.update', ['id' => $requisition->id]) }}" method="post">
                    {{ method_field('PATCH') }}
                    {{ csrf_field() }}
                    <div class="modal-header">
                        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                        <h4 class="modal-title">List of inspection</h4>
                    </div>
                    <div class="modal-body">
                        <select class="form-control" name="inspector_user_id">
                            @foreach($users as $user)
                                <option value="{{ $user->id }}">{{ $user->first_name }} {{ $user->last_name }}</option>
                            @endforeach
                        </select>
                    </div>
                    <div class="modal-footer">
                        <button type="submit" class="btn btn-primary">Save</button>
                        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                    </div>
                </form>
            </div>
        </div>
    </div>

@endsection

@section('script')
    <script src="https://unpkg.com/[email protected]/dist/sweetalert2.all.js"></script>
@endsection

Controller

public function update(Request $request, $requisition)
{
    $approved = Requisition::findOrFail($requisition);
    $approved->approved = 1;
    $approved->inspector_user_id = $request->input('inspector_user_id');
    $approved->save();
    alert()->success('It done', 'OK')->persistent('OK');
    return redirect()->back();
}

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

public function unapproved(Request $request, $id)
{
    $unApproved = Requisition::findOrFail($id);
    $unApproved->approved = 0;
    $unApproved->save();
    alert()->success('It done', 'Cancel')->persistent('OK');
    return redirect()->back();
}

web.php

Route::resource('requisitions', 'RequisitionController');

irankhosravi left a reply on How To Use @foreach In Show Function In Laravel?

OK, only I have a problem, How to use blade?

irankhosravi started a new conversation How To Use @foreach In Show Function In Laravel?

Look at my codes

My blade

<a href="{{ route('infractions.show', ['id' => $requisition->id]) }}">Click here for display data</a>

My Controller

public function show(Requisition $requisitions)
{
    return view('infractions.show', compact('requisitions'));
}

show.blade.php

@foreach($requisitions as $requisition)
    <tr>
        <td>{{ $requisition->id }}</td>
        <td>{{ $requisition->title }}</td>
        <td>{{ $requisition->score }}</td>
    </tr>
@endforeach

A requisition may contain several infractions

Trying to get property of non-object

08 Nov
1 week ago

irankhosravi left a reply on Call To A Member Function Where() On Null

On the next page I got this error

Call to a member function with() on null

irankhosravi left a reply on Call To A Member Function Where() On Null

I tried for about 2 hours but I did not succeed my codes of blade

@forelse ($requisitions as $requisition)
    @forelse($requisition->activities as $activity)
        <tr>
            <td>{{ $requisition->schools->school_name }}</td>
            <td class="translate">{{ $requisition->id  }}</td>
            <td class="translate">{{ $requisition->schools->national_number_founder  }}</td>
            <td>{{ $activity->group->group_name  }}</td>
            <td>{{ $requisition->schools->type  }}</td>
            <td class="translate">{{ $requisition->schools->phone  }}</td>
            <td>{{ $requisition->schools->type }}</td>
            <td>
                <div class="btn-group btn-group-xs">
                    <a  class="btn btn-success btn-xs" data-toggle="modal" data-target="#requisition">Approved</a>
                    <form class="btn-group" action="{{ route('requisitions.unapproved', ['id' => $requisition->id]) }}" method="post">
                        {{ method_field('PATCH') }}
                        {{ csrf_field() }}
                        <button type="submit" class="btn btn-danger btn-xs">Disapproval</button>
                    </form>
                </div>
            </td>
            @empty
                Please go back...
        </tr>
    @endforelse
@endforelse

irankhosravi started a new conversation Call To A Member Function Where() On Null

Call to a member function where() on null

How does this work?

public function index()
{
    $requisitions = Requisition::latest()->first()->where('approved', 1)->paginate(25);
    if ($requisitions == null){
        print "Please go back.";
    } else {
        //$requisitions = Requisition::latest()->first()->where('approved', 1)->schools()->where('city_id', auth()->user()->city_id)->paginate(25);
        return view('Admin.inspection-failed.all', compact('requisitions'));
    }
}

irankhosravi left a reply on How To Save Id In On Checkbox?

I for display show title in next pages

How should I do?

I did the above posts. but I get an error,

07 Nov
1 week ago

irankhosravi started a new conversation How To Save Id In On Checkbox?

I decided to save id to show the violation. Is there a problem with this decision?

blade.php @foreach($infractions as $infraction) {{ $infraction->title }} @endforeach

Controller

public function store(Request $request)
{
    return $request->all();
    $inspection = new Inspection();
    $inspection->infraction_id = $request->infraction_id;
    $inspection->encouragement_id = $request->encouragement_id;
    $inspection->user_id = auth()->user()->id;
    $inspection->requisition_id = $request->input('requisition_id');
    $inspection->save();
    $inspection->requisitions()->update(['status' => 1]);
    return redirect()->route('inspections.index');
}
06 Nov
1 week ago

irankhosravi left a reply on SQLSTATE[01000]: Warning: 1265 Data Truncated For Column 'infraction_id' At Row 1

I changed the infraction_id column to a text

How to save it now?

irankhosravi left a reply on SQLSTATE[01000]: Warning: 1265 Data Truncated For Column 'infraction_id' At Row 1

Ok , How to save it? But I want ids of infractions be on 1 row.

What is the solution?

irankhosravi started a new conversation SQLSTATE[01000]: Warning: 1265 Data Truncated For Column 'infraction_id' At Row 1

I did store checkbox array value into table using below's code

public function store(Request $request)
{
    $infraction_id = $request->infraction_id;
    if(is_array($infraction_id))
    {
        $infraction_id = implode(',', $infraction_id);

    }
    $inspection = new Inspection();
    $inspection->infraction_id = $infraction_id;
    $inspection->encouragement_id = 1;
    $inspection->infraction_data = $request->infractions;
    $inspection->encouragement_data = $request->encouragements;
    $inspection->user_id = auth()->user()->id;
    $inspection->requisition_id = $request->input('requisition_id');
    $inspection->save();
    $inspection->requisitions()->update(['status' => 1]);
    return redirect()->route('inspections.index');
}

create.blade.php

<div class="panel-body">
    <div class="table-responsive">
        <table class="table table-bordered">
            @foreach($infractions as $infraction)
                <tr>
                    <th>{{ $infraction->title }}</th>
                    <td>
                        <input type="checkbox" name="infraction_id[]" value="{{ $infraction->id }}" data-toggle="toggle" data-on="Yes" data-off="No" data-onstyle="success" data-offstyle="danger" data-score="{{ $infraction->score }}">
                    </td>
                </tr>
            @endforeach
        </table>
    </div>
    <div class="text-right">Total:
        <span id="total" class="translate">0</span>
    </div>
</div>

NO 2

02 Nov
2 weeks ago

irankhosravi started a new conversation Take In Laravel Not Working

I want display Activity data in table and display like this: 1, 2, 3

But it showed 1,1,1,2,2,3,3,3

But it should be shown in this way 1, 2, 3.

public function read_activity()
{
    $school_id = SchoolsList::latest();
    $activities = Activity::with('group', 'cluster')
        ->take(1)
        ->where('school_id', '=', $school_id)
        ->get();
    return response()->json($activities);
}

Activity

irankhosravi left a reply on How To Display Json In Blade Laravel

@Cronix

OK, What's the solution? OR how to save the data properly to begin with?

NO 1

NO 2

Look at these two pictures. And tell me which one is right? 1 or 2.

I'm involved with this chart or tables a week

Whatever you say about it. I will do it.

I want to display title.

irankhosravi left a reply on How To Display Json In Blade Laravel

@Cronix

OK, What's the solution? OR how to save the data properly to begin with?

NO 1

NO 2

Look at these two pictures. And tell me which one is right? 1 or 2.

I'm involved with this chart or tables a week

Whatever you say. I will do it.

irankhosravi left a reply on How To Display Json In Blade Laravel

@Cronix

OK, What's the solution? OR how to save the data properly to begin with?

NO 1

NO 2

Look at these two pictures. And tell me which one is right? 1 or 2.

01 Nov
2 weeks ago

irankhosravi left a reply on How To Display Json In Blade Laravel

I'm tired of showing a title off the table of infractions.

irankhosravi left a reply on How To Display Json In Blade Laravel

I'm tired of showing a title off the table of infractions.

irankhosravi left a reply on Increment With Total Not Working

Thanks for the answer, but I want to work the button to increase. And bring them together.

31 Oct
2 weeks ago

irankhosravi started a new conversation Increment With Total Not Working

Look at my codes. Increment with total of score not working

AJAX

function incrementValue(id)
{
    var value = parseInt(document.getElementById('num'+id).value, 10);
    value = isNaN(value) ? 0 : value;
    value++;
    document.getElementById('num'+id).value = value;
    values = value + value;
    document.getElementById('sum').innerHTML = values;
}

My blade

<div class="panel-body">
    <div class="table-responsive">
        <table class="table table-bordered">
            @foreach($encouragements as $encouragement)
                <tr>
                    <th class="translate">{{ $encouragement->title }}</th>
                    <td>
                        <div class="input-group">
                            <input type="text
" min="{{ $encouragement->unit_score }}" max="{{ $encouragement->max_score }}" id="num{{$encouragement->id}}" value="0" class="form-control col-sm-1 translate" name="encouragement[{{ $encouragement->id }}]">
                            <div class="input-group-btn">
                                    <input type="button" onclick="incrementValue({{$encouragement->id}})" class="btn btn-warning" value="افزایش">
                            </div>
                        </div>
                    </td>
                </tr>
            @endforeach
        </table>
    </div>
    <div class="text-right">جمع کل نمره ها:
        <span id="sum" class="translate">0</span>
    </div>
</div>

images

30 Oct
2 weeks ago

irankhosravi started a new conversation Select Option, Checkbox, Option Tags, If They Be Empty

For textboxes and numbers, If they be empty, We send the following error command very easily:

ajax

    parent_fieldset.find('input[type="text"], input[type="number"]').each(function() {
        if( $(this).val() == "" ) {
            $(this).addClass('input-error');
            next_step = false;
        }
        else {
            $(this).removeClass('input-error');
        }
    });

css

.input-error {
    border-color: red;
}

But for select option, checkbox, option tags, if they be empty, How should I do?

29 Oct
2 weeks ago

irankhosravi left a reply on How To Display Json In Blade Laravel

I decided to connect my tables from databases.

connect to database

How to save infraction_id and encouragement_id.

irankhosravi left a reply on How To Display Json In Blade Laravel

I posted a few pictures Did you still notice?

irankhosravi left a reply on How To Display Json In Blade Laravel

I want to display title of from infractions table

28 Oct
2 weeks ago

irankhosravi left a reply on How To Display Json In Blade Laravel

I want to display title of from infractions table

irankhosravi left a reply on Console.log Not Working Checkbox Bootstrap-toggle

Just another question about json https://www.laracasts.com/discuss/channels/laravel/how-to-display-json-in-blade-laravel .

If you can answer it, I do not think I would ask another forum.

irankhosravi left a reply on Console.log Not Working Checkbox Bootstrap-toggle

Thank you so much for a long time

irankhosravi started a new conversation Console.log Not Working Checkbox Bootstrap-toggle

I have score field in table of infractions. And I have many checkboxes. When I checked the chechboxes, The total of scores are collected with ajax. I user http://www.bootstraptoggle.com/

One thing almost like this demo. http://jsfiddle.net/zch11bjo/1

<div class="panel-body">
    <div class="table-responsive">
        <table class="table table-bordered">
            @foreach($infractions as $infraction)
                <tr>
                    <th>{{ $infraction->title }}</th>
                    <td>
                        <input type="checkbox" name="infractions[{{ $infraction->id }}]" value="1" data-toggle="toggle" data-on="Yes" data-off="No" data-onstyle="success" data-offstyle="danger" data-score="{{ $infraction->score }}" onClick="updateTotal();">
                    </td>
                </tr>
            @endforeach
        </table>
    </div>
    <div class="text-right">Total:
        <span id="total">0</span>
    </div>
</div>

Score

ajax

function updateTotal() {
    console.log("Hello World");
    var checked = document.querySelectorAll('input[type=checkbox]:checked');
    var score = 0;

    Array.prototype.forEach.call(checked, function(el, i){
        score += parseInt(el.getAttribute('data-score'));
    });

    console.log(score);
    document.getElementById('total').innerHTML = score;
}

Note: When I changed the following code. The total of sum problem is solved.

<input type="checkbox" data-score="{{ $infraction->score }}" onClick="updateTotal();">

irankhosravi left a reply on How To Get Sum Score When Checked The Checkboxess In Laravel?

I put the code below, my problem has not yet been resolved.

function updateTotal() {
    var checked = document.querySelectorAll('input[type=checkbox]:checked');
    var score = 0;

    Array.prototype.forEach.call(checked, function(el, i){
        score += parseInt(el.getAttribute('data-score'));
    });

    // document.getElementById('total').innerHTML = score;
    document.getElementById('total').innerHTML = document.querySelectorAll('input[type=checkbox]:checked')
        .reduce(total, function(checkbox) {
            return total + checkbox.dataset.score;
        });
}
27 Oct
2 weeks ago

irankhosravi left a reply on How To Get Sum Score When Checked The Checkboxess In Laravel?

I asked data-score with bootstrap-toggle not working How should I do?

irankhosravi started a new conversation How To Get Sum Score When Checked The Checkboxess In Laravel?

I have score field in table of infractions. And I have many checkboxes. When I checked the chechboxes, The total of scores are collected with ajax.

<div class="panel-body">
    <div class="table-responsive">
        <table class="table table-bordered">
            @foreach($infractions as $infraction)
                <tr>
                    <th>{{ $infraction->title }}</th>
                    <td>
                        <input type="checkbox" name="infractions[{{ $infraction->id }}]" value="1" data-toggle="toggle" data-on="بلی" data-off="خیر" data-onstyle="success" data-offstyle="danger" data-score="{{ $infraction->score }}" onClick="updateTotal();">
                    </td>
                </tr>
            @endforeach
        </table>
    </div>
    <div class="text-right">Total:
        <span id="total">

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

Score

ajax

function updateTotal() {
    var checked = document.querySelectorAll('input[type=checkbox]:checked');
    var score = 0;

    Array.prototype.forEach.call(checked, function(el, i){
        score += parseInt(el.getAttribute('data-score'));
    });

    console.log(score);
    document.getElementById('total').innerHTML = score;
}

Note: When I changed the following code. The total of sum problem is solved.

<input type="checkbox" data-score="{{ $infraction->score }}" onClick="updateTotal();">
26 Oct
3 weeks ago

irankhosravi left a reply on Sum Score In Ajax Not Working With Laravel

I do not working with vuejs. I want to ajax, please help.

irankhosravi started a new conversation Sum Score In Ajax Not Working With Laravel

I am creating a system based on an unstable source ie I monitor every time my application can access this source via ajax successfully.

I created a variable and could not understand how I can increment it each time the success is true.

Ajax

function scorePlus (id)
{
    var value = parseInt(document.getElementById('num'+id).value, 10);
    value = isNaN(value) ? 0 : value;
    value++;
    document.getElementById('total').value = value;
}

My blade

<div class="panel-body">
    <div class="table-responsive">
        <table class="table table-bordered">
            @foreach($infractions as $infraction)
                <tr>
                    <th>{{ $infraction->title }}</th>
                    <td>
                        <input type="hidden" id="num{{ $infraction->title }}" name="infractions[{{ $infraction->id }}]" value="0" >
                        <input type="checkbox" value="1" onchange="scorePlus({{ $infraction->score }})" name="infractions[{{ $infraction->id }}]">
                    </td>
                </tr>
            @endforeach
        </table>
    </div>
    <div class="text-right">Total:
        <span id="total">

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

irankhosravi left a reply on How To Display Json In Blade Laravel

Does anyone answer my question?