domantas

domantas

Member Since 1 Month Ago

Experience Points
170
Total
Experience

4,830 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 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
170 XP
Mar
25
2 weeks ago
Activity icon

Started a new Conversation Laravel Count Unique Database Value

I need to perform counting functionality:

  • The User can download only 5 files (total) per 24 hours. For example: User has 5 available downloads today, User downloaded myFile1.txt file and now he has 4 available downloads today, but if he wants to download myFile1.txt file again, he can do it as many times as he wants (still 4 available downloads), but if he downloaded new file myFile2.txt, now he has 3 available downloads.

My question, how to track, how many times a User downloaded a file. This is my code:

    /*
      * $id {string} = file name;
      * $dayStart (Timestamp) = example: 2020-03-25 00:00:00;
      * $dayEnd (Timestamp) = example: 2020-03-26 00:00:00;
      * $total (int) = how much User has downloaded;
      * $response = file download functionality.
      * auth()->user()->dailyDownloads (int) = default value 5.
    */
    public function downloadFile(Request $request, $id){
      $file = storage_path('app/files/') . $id .'.bin';

      // Tracking operation date, find all records in this date interval.
      $dayStart = Carbon::today();
      $dayEnd = Carbon::tomorrow();
      $total = DumpDownloadHistory::distinct('dataset')->where('user_id', auth()->user()->id)->
                      whereBetween('created_at', [$dayStart, $dayEnd])->count();

      $findIfDownloaded = DumpDownloadHistory::distinct('dataset')
->where('user_id', auth()->user()->id)->where('dataset', $id)->count();


      if ($total >= auth()->user()->dailyDownloads) {
        dd('To many downloads');
      }

      if (file_exists($file)) {
          $headers = [
              'Content-Type' => 'application/bin'
          ];

        $response = response()->download($file, $id.'.bin', $headers, 'inline');
        if ($response) {
          // Storing download history to Database
          auth()->user()->downloadHistorys()->create([
            'user_id' => auth()->user()->id,
            'dataset' => $id,
            'user_ip'=> request()->ip()
          ]);
          return $response;

        }
      } else {
          abort(404, 'File not found!');
      }
    }
Mar
24
2 weeks ago
Activity icon

Replied to Laravel Secure Bin Files Download With Limitations

For example today I can download 5 files (total per day), tomorrow I can again download 5 files (total per day), and so on. P.S. In the future I would like to assign how much a user can download files per day.

Activity icon

Started a new Conversation Laravel Secure Bin Files Download With Limitations

Currently I working on secure bin file download. All my bin files are store in Storage/app/files folder. I need to track that the user can download only 5 files in 24 hours. If the user downloaded 5 files per 24 hours, the next time he can download a file are the next day (after 24 hours). Any help will be very useful.

/*
 * $id {string} = file name.
*/
public function downloadFile(Request $request, $id){
      $file = storage_path('app/files/') . $id .'.bin';
      if (file_exists($file)) {
        $user = new User;
        $downloadHistory = new DumpDownloadHistory;

        $downloadHistory->create([
          'user_id' => auth()->user()->id,
          'dataset' => $id,
          'user_ip'=> request()->ip()
        ]);

          $headers = [
              'Content-Type' => 'application/bin'
          ];

        $response = response()->download($file, $id.'.bin', $headers, 'inline');
        if ($response) {
          return $response;
        }
      } else {
          abort(404, 'File not found!');
      }
    }

This is my database of download history:

/**
     * user_id {int} = User id.
     * dataset {string} = file name.
     * user_ip {string} = user ip (User ip address from where the user has downloaded the file)
     */
    public function up()
    {
        Schema::create('dump_download_histories', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('user_id');
            $table->string('dataset');
            $table->string('user_ip');
            $table->timestamps();

            $table->foreign('user_id')->references('id')->on('users');
        });
    }
Mar
18
3 weeks ago
Activity icon

Replied to How To Make Laravel Charts

Who are interested, I found solution. Here is the code:

<?php

namespace App\Http\Controllers;

use App\Content;
use App\Charts\UserLineChart;

use Illuminate\Http\Request;

class ChartController extends Controller
{

  public function index(Request $request)
  {
    $content = Content::where('vei_sn', '23333')->get();
    if ($request->has('date_from') && $request->input('date_from') != '' && $request->has('date_to') && $request->input('date_to') != '') {
        $datefrom = $request->input('date_from');
        $dateto = $request->input('date_to');
        // $content = $content->where(function($query) use ($datefrom, $dateto){
        //                            $query->whereBetween('op_date',array($datefrom, $dateto));
        //                          });
        $content = $content->whereBetween('op_date', [$datefrom, $dateto]);
    }

      $OBD = $content->where('con_type', 'OBD')->count();
      $DC = $content->where('con_type', 'DC')->count();
      $BSL = $content->where('con_type', 'BSL')->count();
      $content = $content->pluck('con_type', 'con_type');

      $chart = new UserLineChart;

      $chart->labels($content->values());

      $chart->dataset('Connections', 'bar', [$OBD, $DC, $BSL])->backgroundColor([
         'red',
         'green',
         'yellow'
      ]);
      return view('chart.index', compact('chart'));
  }
}

Activity icon

Started a new Conversation How To Make Laravel Charts

I am working on a project and I used Laravel Charts library (https://charts.erik.cat/) for making a chart where User selects date from and date to, and from this date range generate chart. I need that from User selected date range (looking to op_date database field) will be generate how many times was used OBD, DC, BSL (this is "con_type" database field data) and generate chart. My code:

namespace App\Http\Controllers;

use App\Content;
use App\Charts\UserLineChart;

use Illuminate\Http\Request;

class ChartController extends Controller
{

  /*
    * vei_sn database field, this is like user ID
    * date_from - HTML input field Date from
    * date_to - HTML input field Date to

  */
  public function index(Request $request)
  {
    $content = Content::where('vei_sn', '23333');
    if ($request->has('date_from') && $request->input('date_from') != '' && $request->has('date_to') && $request->input('date_to') != '') {
        $datefrom = $request->input('date_from');
        $dateto = $request->input('date_to');
        $content = $content->where(function($query) use ($datefrom, $dateto){
                                   $query->whereBetween('op_date',array($datefrom, $dateto));
                                 });
    }
      $OBD = $content->where('con_type', 'OBD')->count();
      $DC = $content->where('con_type', 'DC')->count();
      $BSL = $content->where('con_type', 'BSL')->count();
      $content = $content->pluck('con_type', 'con_type');


      $chart = new UserLineChart;
      $chart->labels($content->values());

      /*
        * Here we enter the values of what will be labels, for example OBD will be 24
      */
      $chart->dataset('Connection types', 'bar', [$OBD, $DC, $BSL])->backgroundColor([
         'red',
         'green',
         'yellow'
      ]);
      return view('chart.index', compact('chart'));
  }
}

My database schema:

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateContentsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('contents', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedBigInteger('file_id');
            $table->integer('vei_sn');
            $table->dateTime('op_full_date');
            $table->date('op_date');
            $table->time('op_time');
            $table->string('con_type');
            // operation
            $table->string('operation');
            $table->string('ecu');
            $table->string('ecu_sub')->nullable();
            $table->string('ecu_sub2')->nullable();
            $table->integer('tokens')->nullable();
            $table->integer('tokens_left')->nullable();
            $table->timestamps();

            $table->foreign('file_id')
                  ->references('id')->on('files')
                  ->onDelete('cascade');
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('contents');
    }
}