kankai

kankai

Member Since 1 Year Ago

Experience Points
8,500
Total
Experience

1,500 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
57
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start-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-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-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist 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 2
8,500 XP
Dec
12
12 hours ago
Activity icon

Replied to How Can I Get Last Two Query With Relationship

The transaction data is like this

GAME ID | Reload | Time
abc          | 30.00    | 11-12-2019
aaa          | 32.00    | 11-12-2019
aaa          | 13.00    | 11-12-2019
abc          | 30.00    | 12-12-2019
acc          | 30.00    | 12-12-2019
acc          | 50.00    | 12-12-2019 
aaa          | 3.00    | 12-12-2019

What i'm need to is show out GAME ID : abc,acc,aaa , today reload amount and last second reload amount.

GAME ID | Today Reload | Previous Reload
abc          | 30.00                | 30.00
acc          | 30.00                | 30.00
acc          | 50.00                | 30.00
aaa          | 3.00                | 13.00

Not sure could you understand this, i try my best explain.

Activity icon

Replied to How Can I Get Last Two Query With Relationship

@bugsysha I have tried can get data from it. But if i add in one condition which only get today data, it can't select others date data.

Dec
09
3 days ago
Activity icon

Started a new Conversation How Can I Get Last Two Query With Relationship

Hi guys,

I'm trying to use eloquent to get last two rows of my data, but i can't figure out how to make it.

id | game_id | value
1  | abc          |10
2  | abc          | 23
3  | cds          | 21
4  | cds          | 44 

So what i need to return is Game ID 'abc' : value = 10 and 'cds' : value = 21

My controller

$doneData = oldwork::with('hasOneWallet','hasLastopup')->where('category', $cat)->where('status', 0)->get();

eloquent model

public function hasOneWallet(){
        return $this->hasOne('App\game_id','game_id','game_id'); 
 }

public function hasLastopup(){
        return $this->hasMany('App\game_id','game_id','game_id')->latest()->take(2); 
 }

I have tried hasLastopup() to get latest 2 result but it fail. Anyway to make this happen? Thanks

Nov
12
1 month ago
Activity icon

Awarded Best Reply on Pass Json To Vue Instead Of __ob__ Observer

There was my mistake in my controller, i just change from

'viewdata' => $view,

to

'viewdata' => $view->render(),

everything solved. Thanks

Activity icon

Replied to Pass Json To Vue Instead Of __ob__ Observer

There was my mistake in my controller, i just change from

'viewdata' => $view,

to

'viewdata' => $view->render(),

everything solved. Thanks

Nov
11
1 month ago
Activity icon

Started a new Conversation Pass Json To Vue Instead Of __ob__ Observer

Hi all,

Currently i'm learning to use laravel vapor but i'm new to vue. What i'm trying to do is upload image to aws S3 and now i'm trying to change my view after uploaded image. Previously i'm using ajax return json to views. But in same method the return return is become ob observer, and i try few ways to convert it back json and still failed.

vue

Vapor.store(document.getElementById('fileItem').files[0], {
                progress: progress => {
                    this.uploadProgress = Math.round(progress * 100);
                }
            }).then(response => {
                axios.post('../../../wallet/imgupload', {
                    uuid: response.uuid,
                    key: response.key,
                    bucket: response.bucket,
                    remark: document.getElementById('remark').value,
                    category: document.getElementById('category').value,
                    uid: document.getElementById('uid').value,
                    name: document.getElementById('fileItem').files[0].name,
                    extension: document.getElementById('fileItem').files[0].type,
                    content_type: document.getElementById('fileItem').files[0].type,  
                }).then (response => {
                    var test = JSON.stringify(response.data)
                    console.log(test)
                    var abc = JSON.parse(response)
                    console.log(abc)
                }).catch (response => {
                    console.log(response)
                });
            });

in my controller

 Storage::copy($request->input('key'), str_replace('tmp/','', $request->input('key')));

        
        imgData::insert([
            'uid' => $request->input('uid'),
            'category' => $request->input('category'),
            'path' => $request->input('key'),
            'remarks' => $request->input('remark'),
            'status' => 0,
            'uploaded_by' => \Auth::user()->name,
            'uploaded_at' => now(),
        ]);


        $imgData = imgData::where('uid', $uid)->where('status', 0)->get();

        $view = view('wallet.apps', compact('imgData'));

        return response()->json([
            'return' => 'view',
            'viewdata' => $view,
        ]);
Nov
07
1 month ago
Activity icon

Replied to How To Pass Variable To Throttle Method

@bobbybouwmann Thank you very much, appreciate!

Activity icon

Started a new Conversation How To Pass Variable To Throttle Method

Hi,

I'm trying to limit user request time to my application, so i use redis throttle method. But i get a issue that it can't get my variable to this function, is there anyway to pass variable to this function?

$userName = $request->name;
Redis::throttle('key')->allow(1)->every(1)->then(function () {
        user::insert([
        'name' => $userName,
    ]);
 }, function () {
 return $this->release(1);

Here are my current code that found error $userName is not defined, thanks

Oct
05
2 months ago
Activity icon

Replied to Laravel Develop Idle Web Game

Oh i see, i'm not familiar with these. I thought it's relate to hardware and software of i put it on.

Oct
04
2 months ago
Activity icon

Replied to Laravel Develop Idle Web Game

Yup, will use laravel as backend. But it i just use laravel+apache+some javascript will it make server response slow to update/insert database?

Activity icon

Started a new Conversation Laravel Develop Idle Web Game

Hi All,

I'm planning a project which is develop an idle html5 web game with simple chat system and player character can get exp in realtime. i need some advice what should i use to develop this project? I had some research in google some of people using node.js and vue. Any other suggestion? Thanks

Oct
02
2 months ago
Activity icon

Started a new Conversation Database Multiple Table Insert/update Issue

Hi all,

I facing an issue that controller insert/update multiple tables failure sometimes.

tableA::insert([
    'name' => 'nameA',
    'status' => 0,
]);

tableB::insert([
    'name' => 'nameB',
    'status' => 0,
]);

Not sure is network problem or my application problem, it will miss out to insert data sometime. It's there anyway to avoid this happen? Thanks

Sep
23
2 months ago
Activity icon

Replied to Bootstrap Datepicker

Thank @alexdotdev , i solved this issue. It has issue in controller that makes laravel define it as wrong format date.

I change my view to your code as mention and controller to this

 // $dob = date("Y-m-d", strtotime($request->dob));
// $dob = $request->dob;
$dob = strtr($request->dob_editinput, '/', '-');
$dob = date("Y-m-d", strtotime($dob));
Sep
12
3 months ago
Activity icon

Started a new Conversation Bootstrap Datepicker

Hi guys,

I have a issue when i use bootstrap datepicker change date format to 'dd/mm/yyyy'. It will return 1970-01-01, i guess it get wrong timestamp format so it return this result. Anyway to change this dateformat?

These is my code

<div class="input-group">
        <input autocomplete="off" name="dob" type="text" class="form-control mydatepicker" placeholder="Date of Birth" required="true">
          <div class="input-group-append">
                      <span class="input-group-text"><i class="fa fa-calendar"></i></span>
          </div>
 </div>
jQuery('.mydatepicker').datepicker({
         format: 'dd/mm/yyyy',
        autoclose: true,
        todayHighlight: true
    });
Sep
04
3 months ago
Activity icon

Started a new Conversation Relation With Select

Hi Guys,

Is there anyway to filter my huge data by using relation and select certain column?

Controller

$reloadList = oldwork::where('done_time','<=', $dateFrom)->where('game_id','!=','')->where('status',0)->orWhere('done_time','>=', $dateTo)->where('game_id','!=','')->where('status', 0)->groupBy('game_id')->select('game_id')->get();

return $noreloadList->wallet;

oldwork Model

 public function wallet(){
        return $this->hasOne('App\wallet','wallet','wallet'); 
    }

I have around 4k non-repeat game_id in $reloadList, but after i try to use 'wallet' relation bind to these data, it come out i guess N+1 problem or data too huge.

Aug
29
3 months ago
Activity icon

Replied to Anyway To Pass Parameter Into Eloquent Function?

@tisuchi @martinbean I changed my code something like this, is it a correct way to solve this issue?

 $data = game_id::where('wallet', $inputValue)->get();
 $detail = $data[0]->game;
return $detail->where('done_time','>=', date('Y-m-d'));

Now i can get data but only single 'game_id' with '$data[0]' but i have 6 game_id. Is that need to push in array only i can get all game_id data?

Aug
27
3 months ago
Activity icon

Replied to Anyway To Pass Parameter Into Eloquent Function?

Thanks @tisuchi @siangboon , this is new thing to me. I think need some time to study it. =)

Aug
26
3 months ago
Activity icon

Started a new Conversation Anyway To Pass Parameter Into Eloquent Function?

Hi guys,

I'm new to eloquent, is that anyway to pass parameter to eloquent function?

current game_id model

 public function detail(){
        return $this->hasMany('App\gamedata','game_id','game_id')->where('status',0);
 }

my controller

     $inputValue = $request->wallet;
        $data = game_id::with('detail')->where('wallet', $inputValue)->get();
    return view('playerfilter', compact('data'));

What i need is pass select date from controller to model there, something like this.

public function detail($date){
        return $this->hasMany('App\gamedata','game_id','game_id')->whereDate('created_at', $date)->where('status',0);
 }
Aug
07
4 months ago
Activity icon

Replied to Use Chunk To Get Query Still Slow

If use limit(400) only will get 400 rows? If i need to check all records in selected month it will be more than 5,000

Aug
06
4 months ago
Activity icon

Started a new Conversation Use Chunk To Get Query Still Slow

Hi guys,

I building a system that need to check a records, it's output around 5,000 rows. When i use dd($data) it trace out very fast in 200ms, but when goes to view it took around 10seconds to finish loaded. I try to use chunk to get query, it had improve loaded out speed but still slow.

I try to load only {{ $row-id }} per row it become more fast, it there any problem with my code? Will it be frontend problem to cause it loading slow?

controller

$data = oldwork::where('category',$cat)->where('status',0)->where('done_time','>=', $dateFrom)->where('done_time','<=', $dateTo)->get();

$data = $data->chunk(400);

views

@foreach($data as $chunk)
                                                @foreach($chunk as $row)
                                                    <tr>
                                                        <td scope="col">
                                                            <!-- {{ $row->id }} -->
                                                        </td>
                                                        <td scope="col">
                                                            {{ $row->game_id }}
                                                        </td>
                                                        <td scope="col">
                                                            {{ $row->reference }}
                                                        </td>
                                                        <td scope="col">
                                                            {{ $row->bank }}
                                                        </td>
                                                        <td scope="col">
                                                            {{ $row->capital }}
                                                        </td>
                                                        <td scope="col">
                                                            {{ $row->done_time }}
                                                        </td>
                                                    </tr>
                                                @endforeach
                                            @endforeach
                                                
Jul
31
4 months ago
Activity icon

Replied to New Database Get Data Very Slow

If i need to handle more than 50 items, beside adding indexes what else can i do with my code or database?

Activity icon

Started a new Conversation New Database Get Data Very Slow

Hi guys,

I'm bad with database manage, before that i create a management system to record sales data. It's run quite smoothly with normal php and html codes. Then now i upgraded myself and created a new one included javascript and try model to get database data.

But i found out it loaded very slow and took 10800ms to finish it (the old one took 420ms), not sure what's wrong with it.

the old one

$data = DB::table('oldworks')->where('category',$cat)->where('status',0)->where('created_at','>=', $getdateValuefrom)->where('created_at','<=', $getdateValueto)->get();

new

use Illuminate\Database\Eloquent\Model;
class oldwork extends Model
{
    //
    protected $table = 'oldworks';
}

 $data = oldwork::where('category', $cat)->where('status', 0)->where('created_at','>=',$getdateValuefrom)->where('created_at','<',$getdateValueto)->get();

Both of the database are same

Jun
27
5 months ago
Activity icon

Replied to Unicode Problem, Output Strange Words When In Chinese

Hi Guys,

I found solution from google, it change the words unicode when i "loadHTML" , "saveHTML". I added in these code and solved it.

$doc->loadHTML('<?xml encoding="UTF-8">'. $detail);
 $detail = '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">';
        $detail .= $doc->saveHTML( $doc->documentElement ); // important!
Jun
26
5 months ago
Activity icon

Replied to Unicode Problem, Output Strange Words When In Chinese

@BOBBYBOUWMANN - yaya, i just type chinese text and images into it and db there come out these strange words

Jun
23
5 months ago
Activity icon

Started a new Conversation Unicode Problem, Output Strange Words When In Chinese

Hi guys,

I'm using summernote editor post content and upload image to my website. But i found out unicode problem and save strange words to my db.

常勇和舒森不仅是男神女神,也是超有才华的YouTuber哦!从高中毕业到大学毕业,两人都在彼此的身边!【高中到大å­

i suspect these code will affect to output but i'm not good with these

$detail=$request->input('detail');

$dom = new \DomDocument();

$dom->loadHtml($detail, LIBXML_HTML_NOIMPLIED | LIBXML_HTML_NODEFDTD); 
        
$images = $dom->getElementsByTagName('img');

foreach($images as $k => $img){

            $data = $img->getAttribute('src');

            list($type, $data) = explode(';', $data);

            list(, $data)      = explode(',', $data);

            $data = base64_decode($data);

            $image_name= "/upload/" .time().$k.'.jpg';


            $path = public_path() . $image_name;

            file_put_contents($path, $data);

            $img->removeAttribute('src');

            $img->setAttribute('src', $image_name);

        }

        $detail = $dom->saveHTML();
Jun
20
5 months ago
Activity icon

Replied to Return Html Code To View With Javascript Have Repeat Issue

Hi guys, i solved the problem. It's because view structure cause post form POST it several times. I restructure the view and problem solved, thanks.

Activity icon

Replied to Return Html Code To View With Javascript Have Repeat Issue

@CRONIX - It still will repeat view, i think my view structure have problem.

Jun
19
5 months ago
Activity icon

Started a new Conversation Return Html Code To View With Javascript Have Repeat Issue

Hi guys,

I have use ajax post and get return data to views, but i notice that it have repeat my html code issue.

Controller

$view = view ('content', compact('todayDate'));
return $view;

Ajax

success: function(response){
    console.log('test')
    data(response);
 },


function data(data){
    $('#content').empty().html(data);
}   

View

<form id="selectDate" action="" method="">
                                            <li>
                                                <div class="input-group">
                                                    <input autocomplete="off" id="date_from" name="date_from" type="text" class="form-control mydatepicker" placeholder="From current date">
                                                    <div class="input-group-append">
                                                        <span class="input-group-text"><i class="fa fa-calendar"></i></span>
                                                    </div>
                                                </div>
                                            </li>
                                            <li>
                                                <div class="input-group">
                                                    <input autocomplete="off" id="date_to" name="date_to" type="text" class="form-control mydatepicker" placeholder="To current date">
                                                    <div class="input-group-append">
                                                        <span class="input-group-text"><i class="fa fa-calendar"></i></span>
                                                    </div>
                                                </div>
                                            </li>
                                            <li>
                                                <button type="submit" class="btn btn-info">Check</button>
                                            </li>
                                        </form>

I try to use console 'test' at the first time, it come out once 'test'. The second time it will come out twice 'test', and the third time it will come out 3 times.

Jun
17
5 months ago
Activity icon

Replied to How To Get New Data With Ajax Post?

@REACHED - It show fully of updated html code

Activity icon

Started a new Conversation How To Get New Data With Ajax Post?

Hi guys,

I'm new with ajax. I try to make an query about searching data from date to date, i can create post datepicker input to controller but don't know how to get updated data return back to views.

Here are my code, thank you.

Views:

<input autocomplete="off" id="date_from" name="date_from" type="text" class="form-control mydatepicker" placeholder="From current date">
<input autocomplete="off" id="date_to" name="date_to" type="text" class="form-control mydatepicker" placeholder="To current date">

<script type="text/javascript">
        submitForm('#selectDate','{{ url("analysis/data") }}')

    function init(){
            $.get('/analysis/datainfo', function(data){
                $('#datainfo').empty().html(data)
            })
        }
    
        init()
</script>

Javascript:

function submitForm(){
  var parameterLength = arguments.length;
  var formID = arguments[0];
  var postUrl = arguments[1];
  
  $(document).ready(function() {
    $(formID).submit(function (ev) {
         $.ajaxSetup({
             headers: {
                 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
             }
        });
        $.ajax({
            method: 'POST', // Type of response and matches what we said in the route
            url: postUrl, // This is the url we gave in the route
            data:$(formID).serialize(), // a JSON object to send back
            success: function(response){ // What to do if we succeed
              console.log(response);
              result(response);
            },
            error: function(jqXHR, textStatus, errorThrown) { // What to do if we fail

              console.log(JSON.stringify(jqXHR));
              console.log("AJAX error: " + textStatus + ' : ' + errorThrown);
            },
        });
        ev.preventDefault();
    });
  });
}

controller:

public function show(Request $request)
    {
        //
        $start = $request->date_from;
        $end = $request->date_to;

        if ($start > $end) {
            $msg = 'Invalid Start/End date setting';
            $status = 'error';
            $timer = 2000;
        }else{
            $todayDate = $start;
            // $todayDate = date('Y-m-d');
            $categoryList = category::where('status', 0)->get();
            $dailyReport = report::where('type', 0)->whereDate('created_at', $todayDate)->get();
          

            $msg = 'Operation successful';
            $status = 'success';
            $timer = 1500;

            return response()->json([
                // 'effect' => 'updated',
                'msg' => $msg,
                'status' => $status,
                'timer' => $timer,
                'showConfirm' => false,
                // 'btnTxt' => 'Continue?',
                // 'confirmBtn' => '#ffcc00',
                'position' => 'bottom-end',
                // 'showCancel' => true,
                // 'cancelBtn' => '#ff0000',
                'mini' => true,
                // 'debug' => $dateFrom,
            ]);  


            return view ('data', compact('todayDate','categoryList','dailyReport'));
           
        }     
Jun
09
6 months ago
Activity icon

Replied to Get Element ID Value Under Element ID

@JOHNBRAUN - Thanks @johnbraun , solved the problem =)