vumanhtrung

vumanhtrung

Software Engineer at Freelancer

Member Since 1 Week Ago

Saigon, VN

Experience Points
1,090
Total
Experience

3,910 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
2
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

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

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

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

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    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 Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

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

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

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

Level 1
1,090 XP
Sep
17
2 days ago
Activity icon

Replied to Migrate Without Lose Data

You need to create new migration for adding column

php artisan make:migration add_votes_to_users_table --table=users

Add new column

Schema::table('users', function (Blueprint $table) {
    $table->integer('votes');
});

Final, running artisan

php artisan migrate
Sep
13
6 days ago
Activity icon

Replied to Authentication Controllers

You can check guard and custom redirect in app\Http\Middleware\RedirectIfAuthenticated.php

<?php

namespace App\Http\Middleware;

use App\Providers\RouteServiceProvider;
use Closure;
use Illuminate\Support\Facades\Auth;

class RedirectIfAuthenticated
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @param  string[]|null  ...$guards
     * @return mixed
     */
    public function handle($request, Closure $next, ...$guards)
    {
        $guards = empty($guards) ? [null] : $guards;

        foreach ($guards as $guard) {
            if (Auth::guard($guard)->check()) {
                // return redirect(RouteServiceProvider::HOME);
                return redirect()->route('your_custom_route');
            }
        }

        return $next($request);
    }
}
Activity icon

Replied to Pros And Cons Of Using Ajax In L7

First, in logic code, you need to write a function that return json data when call by ajax.

public function datatables(Request $request)
    {
        $start = 0;
        $length = 10;
        $draw = 1;
        $sortCol = 'id';
        $sortDir = 'DESC';
        $keyword = '';
        $fields = [];
        if ($request->isMethod('post')) {
            $start = $request->start;
            $length = $request->length;
            $draw = $request->draw;
            $order = $request->order;
            $keyword = $request->search['value'];
            if (isset($order[0]['column']) && $order[0]['column'] >= 0) {
                $columns = $request->columns;
                $key = $order[0]['column'];
                $sortCol = $columns[$key]['data'];
                $sortDir = strtoupper($order[0]['dir']);
            }
            $keys = array_keys($request->columns);
            if (is_countable($keys)) {
                foreach ($keys as $k) {
                    if ($request->columns[$k]['searchable'] === 'true') {
                        $fields[] = $request->columns[$k]['data'];
                    }
                }
            }
        }
        $totalRecords = Tag::count();
        $totalFilteredRecords = $totalRecords;
        $tag = Tag::offset($start)->limit($length)->orderBy($sortCol, $sortDir);
        $totalFields = count($fields);
        if (!empty($keyword) && $totalFields > 0) {
            $tag->where($fields[0], 'LIKE', "%{$keyword}%");
            if ($totalFields > 1) {
                for ($i = 1; $i < $totalFields; ++$i) {
                    $tag->orWhere($fields[$i], 'LIKE', "%{$keyword}%");
                }
            }
            $totalFilteredRecords = $tag->count();
        }
        $records = $tag->get();

        return response()->json([
            'draw' => $draw,
            'recordsTotal' => $totalRecords,
            'recordsFiltered' => $totalFilteredRecords,
            'data' => $records,
        ]);
    }

And custom blade template

@extends('backend.layouts.master')
@section('content')

<div class="content-wrapper">
    <section class="content-header">
        <div class="container-fluid">
            <div class="row mb-2">
                <div class="col-sm-6">
                    <h1>{{ __('Tags') }}</h1>
                </div>
                <div class="col-sm-6">
                    <ol class="breadcrumb float-sm-right">
                        <li class="breadcrumb-item"><a href="{{ route('admin.dashboard') }}">{{ __('Home') }}</a></li>
                        <li class="breadcrumb-item active">{{ __('Tags') }}</li>
                    </ol>
                </div>
            </div>
        </div>
    </section>
    <section class="content">
        <div class="container-fluid">
        <div class="row">
            <div class="col-12">
                <div class="card">
                    <x-alert type="success" class="alert alert-success alert-dismissible fade show m-2" />
                    <x-alert type="error" class="alert alert-danger alert-dismissible fade show m-2" />
                    <div class="card-header">
                        <h3 class="card-title">{{ __('Tags') }}</h3>
                        <div class="card-tools">
                            <a href="{{ route('admin.tags.create') }}" class="btn btn-primary">{{ __('Create a Tag') }}</a>
                        </div>
                    </div>
                    <div class="card-body">
                        @csrf
                        <table id="data_tables" class="table table-bordered table-striped">
                            <thead>
                                <tr>
                                    <th>{{ __('Id') }}</th>
                                    <th>{{ __('Name') }}</th>
                                    <th>{{ __('Slug') }}</th>
                                    <th>{{ __('Status') }}</th>
                                    <th>{{ __('Action') }}</th>
                                </tr>
                            </thead>
                            <tfoot>
                                <tr>
                                    <th>{{ __('Id') }}</th>
                                    <th>{{ __('Name') }}</th>
                                    <th>{{ __('Slug') }}</th>
                                    <th>{{ __('Status') }}</th>
                                    <th>{{ __('Action') }}</th>
                                </tr>
                            </tfoot>
                        </table>
                    </div>
                </div>
            </div>
        </div>
        </div>
    </section>
</div>
<link href="//gitcdn.github.io/bootstrap-toggle/2.2.2/css/bootstrap-toggle.min.css" rel="stylesheet"/>
<script src="//gitcdn.github.io/bootstrap-toggle/2.2.2/js/bootstrap-toggle.min.js"></script>
<link href="//cdn.datatables.net/1.10.21/css/jquery.dataTables.min.css" rel="stylesheet" />
<script src="//cdn.datatables.net/1.10.21/js/jquery.dataTables.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]"></script>
<script>
var data_tables;
$(document).ready(function() {
    var data_tables = $('#data_tables').DataTable({
        stateSave: true,
        orderCellsTop: true,
        fixedHeader: true,
        pageLength: 10,
        lengthMenu: [
            [10, 20, 30, 50],
            [10, 20, 30, 50]
        ],
        processing: true,
        serverSide: true,
        searching: true,
        order: [
            [0, 'desc']
        ],
        ajax: {
            'url': "{{ route('admin.tags.datatables') }}",
            'type': 'POST',
            'data': function(data) {
                data._token = $('input[name="_token"]').val()
            }
        },
        columns: [
            { 'data': 'id', 'width': '5%', 'orderable': true, 'searchable': false },
            { 'data': 'name', 'width': '35%', 'orderable': true },
            { 'data': 'slug', 'width': '10%', 'orderable': true },
            { 'data': 'status', 'width': '5%', 'orderable': false, 'searchable': false },
            { 'data': null, 'width': '10%', 'orderable': false, 'searchable': false }
        ],
        columnDefs: [
            {
                targets: 3,
                render: function(data, type, row) {
                    if (type === 'display') {
                        return '<input type="checkbox" class="editor-active" />';
                    }
                    return data;
                },
                className: "dt-body-center"
            },
            {
                targets: 4,
                render: function(data, type, row) {
                    item_id = row.id;
                    href = "{{ route('admin.tags.edit', 'ITEM_ID') }}".replace(/ITEM_ID/g, item_id);
                    return '<a href="' + href + '"><i class="far fa-edit"></i></a> ' +
                    '<a href="javascript:void(0)" class="remove"><i class="far fa-trash-alt"></i></a>';
                },
                className: "dt-body-center"
            }
        ],
        rowCallback: function(row, data) {
            $('input.editor-active', row).prop('checked', data.status == 1).bootstrapToggle({
                size: 'small',
                on: 'Active',
                off: 'Inactive',
                onstyle: 'success',
                offstyle: 'danger',
            });
        }
    });
    $('#data_tables').on('change', 'input.editor-active', function() {
        $(".alert").each(function(){
            $(this).remove();
        });
        status = $(this).prop('checked') ? 1 : 0;
        var record = data_tables.row($(this).closest('tr')).data();
        $.ajax({
            type: 'POST',
            url: "{{ route('admin.tags.update_status') }}",
            data: {
                _token: $('input[name="_token"]').val(),
                id: record.id,
                status: status
            },
            beforeSend: function() {},
            success: function(resp) {
                if (resp.status === 'success') {
                    $('.card').prepend('<div role="alert" class="alert alert-success alert-dismissible fade show m-2">' + resp.message + '</div>');
                }
            },
            complete: function() {}
        });
    });
    $('#data_tables').on('click', 'a.remove', function() {
        var record = data_tables.row($(this).closest('tr')).data();
        Swal.fire({
            title: "{{__('Are you sure?')}}",
            text: "{!!__('You won\'t be able to revert this!')!!}",
            icon: 'warning',
            showCancelButton: true,
            confirmButtonColor: '#3085d6',
            cancelButtonColor: '#d33',
            confirmButtonText: "{{__('Yes, delete it!')}}"
        }).then((result) => {
            if (result.value) {
                url = "{{ route('admin.tags.destroy', 'ITEM_ID') }}".replace(/ITEM_ID/g, record.id);
                fetch(url, {
                    method: 'DELETE',
                    headers: {
                        "Content-Type": "application/json; charset=utf-8",
                        "X-CSRF-TOKEN": $('input[name="_token"]').val()
                    },
                    body: JSON.stringify({
                        '_token': $('input[name="_token"]').val()
                    })
                })
                .then(r => r.json())
                .then(r => {
                    window.location.href = r.url;
                }).catch(error => console.error('Error', error))
            }
        })
    });
});
</script>

@endsection

Sep
12
1 week ago
Activity icon

Awarded Best Reply on Pros And Cons Of Using Ajax In L7

You could be used Datatables solution for CRUD.

Reference:

https://github.com/yajra/laravel-datatables

https://datatables.net

Sep
10
1 week ago
Activity icon

Replied to %LIKE% But Prefer Exact Match

Use orderBy()

$dbData = City::where('name', 'like', '%'.$data.'%')->orderBy('name', 'asc')->limit(10)->get();

Activity icon

Replied to Get Json Data In Blade

You can use withInput()

return back()->withInput(['ParamData' => $ParamData]);

Activity icon

Replied to Pros And Cons Of Using Ajax In L7

You could be used Datatables solution for CRUD.

Reference:

https://github.com/yajra/laravel-datatables

https://datatables.net

Activity icon

Replied to Laravel 7 Pagination Display Blank Next Pages After Filter

I think you should be installed Laravel Telescope package for debug.

Reference: https://laravel.com/docs/8.x/telescope

Sep
09
1 week ago
Activity icon

Replied to Laravel 7 Pagination Display Blank Next Pages After Filter

You can use dump() for test

dump($categories->links())

dump($categories->nextPageUrl())

Reference: https://laravel.com/docs/7.x/pagination#paginator-instance-methods

Activity icon

Awarded Best Reply on Laravel 8: Jetstream; Livewire; Inertia Error

The Laravel 8 docs not clear. You can fix it by following commands:

php artisan jetstream:install livewire

npm install && npm run dev

Reference: https://github.com/laravel/jetstream#installation

Activity icon

Replied to Laravel 8: Jetstream; Livewire; Inertia Error

The Laravel 8 docs not clear. You can fix it by following commands:

php artisan jetstream:install livewire

npm install && npm run dev

Reference: https://github.com/laravel/jetstream#installation