<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: jasuke-dev</title>
    <description>The latest articles on Forem by jasuke-dev (@ilham_s).</description>
    <link>https://forem.com/ilham_s</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F825224%2Fc21997c5-999f-4796-9935-ece0d065c85c.png</url>
      <title>Forem: jasuke-dev</title>
      <link>https://forem.com/ilham_s</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/ilham_s"/>
    <language>en</language>
    <item>
      <title>Auto reload in laravel using laravel-mix and browserSync</title>
      <dc:creator>jasuke-dev</dc:creator>
      <pubDate>Sun, 25 Dec 2022 05:30:46 +0000</pubDate>
      <link>https://forem.com/ilham_s/auto-reload-in-laravel-using-laravel-mix-and-browsersync-1j6p</link>
      <guid>https://forem.com/ilham_s/auto-reload-in-laravel-using-laravel-mix-and-browsersync-1j6p</guid>
      <description>&lt;p&gt;if you want to auto reload the page every time your project file change you can use browserSync&lt;/p&gt;

&lt;h3&gt;
  
  
  Prerequisite
&lt;/h3&gt;

&lt;p&gt;in this method you must already have laravel project and install and use laravel-mix&lt;/p&gt;

&lt;h3&gt;
  
  
  Install browserSync and browserSync web[ack plugin
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install browser-sync browser-sync-webpack-plugin --save-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  add following code to webpack.mix.js
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;mix.browserSync('127.0.0.1:8000');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  then you can watch your project
&lt;/h3&gt;

&lt;p&gt;watch your project with npm run watch (mix watch)&lt;/p&gt;

</description>
      <category>tutorial</category>
    </item>
    <item>
      <title>Add TailwindCss to laravel use laravel-mix</title>
      <dc:creator>jasuke-dev</dc:creator>
      <pubDate>Sun, 25 Dec 2022 05:14:07 +0000</pubDate>
      <link>https://forem.com/ilham_s/add-tailwindcss-to-laravel-use-laravel-mix-hik</link>
      <guid>https://forem.com/ilham_s/add-tailwindcss-to-laravel-use-laravel-mix-hik</guid>
      <description>&lt;p&gt;Here i will tell you how to add tailwindCss to your laravel project.&lt;/p&gt;

&lt;h3&gt;
  
  
  First install tailwindCss, postCss and autoprefixer packages to your project
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install -D tailwindcss postcss autoprefixer
npx tailwindcss init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Second add tailwindCss to laravel-mix configuration
&lt;/h3&gt;

&lt;p&gt;on webpack.mix.js add following code&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const mix = require('laravel-mix');

mix.js("resources/js/app.js", "public/js")
  .postCss("resources/css/app.css", "public/css", [
    require("tailwindcss"),
  ]);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Configure your template paths
&lt;/h3&gt;

&lt;p&gt;Add the paths to all of your template files in your tailwind.config.js file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;module.exports = {
  content: [
    "./resources/**/*.blade.php",
    "./resources/**/*.js",
    "./resources/**/*.vue",
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Add the Tailwind directives to your CSS
&lt;/h3&gt;

&lt;p&gt;at './resource/css/app.css add this tailwind directives&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@tailwind base;
@tailwind components;
@tailwind utilities;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Then add link style on your blade file
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  &amp;lt;link rel="stylesheet" href="{{ asset('css/app.css') }}"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Lastly you can compile laravel-mix
&lt;/h3&gt;

&lt;p&gt;make sure you have alredy set "npm run watch:mix" watch on package.json&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run watch
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can use tailwindcss on your laravel project&lt;/p&gt;

</description>
      <category>frontend</category>
      <category>codequality</category>
    </item>
    <item>
      <title>Import Data From CSV with pdf file Using JSON and Base 64 in Laravel</title>
      <dc:creator>jasuke-dev</dc:creator>
      <pubDate>Sun, 06 Mar 2022 08:57:51 +0000</pubDate>
      <link>https://forem.com/ilham_s/import-data-from-csv-with-pdf-file-using-json-and-base-64-in-laravel-147a</link>
      <guid>https://forem.com/ilham_s/import-data-from-csv-with-pdf-file-using-json-and-base-64-in-laravel-147a</guid>
      <description>&lt;p&gt;Recently I have a problem that required importing data in CSV that in every row of the data related to one pdf file. Here examples of data in csv&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--_WvxsPZ---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a2y6p80922l7v2wvejwg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--_WvxsPZ---/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/a2y6p80922l7v2wvejwg.png" alt="Examples data in csv file" width="652" height="121"&gt;&lt;/a&gt;&lt;br&gt;
The pdf file has name of data in column accno&lt;/p&gt;

&lt;p&gt;The solution that I found is to convert csv data to JSON file along with converting pdf file to base 64 (This is done in order to be able to save the pdf file into JSON). Here the code to converting csv file to JSON with Python.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import csv
import base64
import json

with open('data_collection.csv', 'r') as datainput:
    reader = csv.reader(datainput, delimiter=';')

    list = []
    row = next(reader)

    for row in reader:
        with open('{}.pdf'.format(row[0]), "rb") as pdf_file:
            base64_byte = base64.b64encode(pdf_file.read())
            base64_string = base64_byte.decode('utf-8')

            dict = {
                'inventory_code' : row[0],
                'title' : row[1],
                'year' : row[2],
                'isbn' : row[3],
                'base64file' : base64_string
            }
            list.append(dict)

    jsonString = json.dumps(list)
    jsonFile = open("data.json", "w")
    jsonFile.write(jsonString)
    jsonFile.close()
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So after that I have data.json that contain data from csv + base 64 from pdf file&lt;/p&gt;

&lt;h2&gt;
  
  
  In Laravel Project
&lt;/h2&gt;

&lt;h3&gt;
  
  
  blade file
&lt;/h3&gt;

&lt;p&gt;Just simple input file that send POST request&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;....
    &amp;lt;form method="POST" action="/import" enctype="multipart/form-data"&amp;gt;
        @csrf
        &amp;lt;input type='file' name="file"/&amp;gt;
        &amp;lt;button type="submit"&amp;gt;Import Data&amp;lt;/button&amp;gt;
    &amp;lt;/form&amp;gt;              
....
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Web.php
&lt;/h3&gt;

&lt;p&gt;Define Route to handle POST Request in web.php&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Route::post('/import', [importController::class, 'index']);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  ImportController
&lt;/h3&gt;

&lt;p&gt;Make import Controller to handle JSON file and storing the logic to save data in the model&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;?php

namespace App\Http\Controllers;

use App\Models\Book;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Storage;

class importController extends Controller
{
    public function index(){
        $JSONfile = file_get_contents(request()-&amp;gt;file('file'));
        $JSON_decode = json_decode($JSONfile);

        foreach ($JSON_decode as $row) 
        {
            //decode bs64 string to bytes
            $b64_pdf = utf8_decode($row-&amp;gt;base64file);

            //randomize name 
            $RandName = Str::random(10).'.'.'pdf';
            $pathName = $RandName;

            //bring back pdf file from base 64 and save it in public directory
            Storage::disk('public')-&amp;gt;put($RandName, base64_decode($b64_pdf, true));

            //save data to table
            Book::create([
                'accno' =&amp;gt; empty($row-&amp;gt;accno) ? NULL : $row-&amp;gt;accno, 
                'title'    =&amp;gt; empty($row-&amp;gt;title) ? NULL : $row-&amp;gt;title, 
                'year'    =&amp;gt; empty($row-&amp;gt;year) ? NULL : $row-&amp;gt;year, 
                'isbn'    =&amp;gt; empty($row-&amp;gt;isbn) ? NULL : $row-&amp;gt;isbn, 
                'path'    =&amp;gt; $pathName, 

            ]);
        }
    }
}

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can import your data along with pdf file simultaneously, if you have another solution please tell me in comment section thanks&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>base</category>
      <category>csv</category>
      <category>json</category>
    </item>
    <item>
      <title>Add Tom Select to Laravel using Laravel MIX</title>
      <dc:creator>jasuke-dev</dc:creator>
      <pubDate>Fri, 04 Mar 2022 07:48:40 +0000</pubDate>
      <link>https://forem.com/ilham_s/add-tom-select-to-laravel-using-laravel-mix-2321</link>
      <guid>https://forem.com/ilham_s/add-tom-select-to-laravel-using-laravel-mix-2321</guid>
      <description>&lt;p&gt;This is how to add Tom Select package to youre laravel project&lt;/p&gt;

&lt;h2&gt;
  
  
  Installing Tom Select
&lt;/h2&gt;

&lt;p&gt;Open terminal in youre laravel project and install the package&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i tom-select
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Applying Tom Select JS
&lt;/h2&gt;

&lt;p&gt;open /resources/js/app.js and add Tom Select js in there&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;window.TomSelect = require('tom-select')
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Applying Tom Select CSS
&lt;/h2&gt;

&lt;p&gt;Tom Select functionality will not work with out the css file, add Tom Select CSS to /resources/css/app.css&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;...
@import '/node_modules/tom-select/dist/css/tom-select.default.css';
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There are many css file, select what you like&lt;/p&gt;

&lt;h2&gt;
  
  
  Build laravel mix
&lt;/h2&gt;



&lt;p&gt;&lt;code&gt;npm run development&lt;/code&gt;&lt;br&gt;
&lt;/p&gt;

&lt;h2&gt;
  
  
  Add app.js and app.css to blade file
&lt;/h2&gt;

&lt;p&gt;Dont forget to add app.js and app.css from public folder&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;link rel="stylesheet" href="{{ mix('css/app.css') }}"&amp;gt;
&amp;lt;script src="{{ asset('js/app.js') }}" defer&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Done Tom Select has been succesfully add to youre laravel project&lt;/p&gt;

</description>
      <category>laravel</category>
      <category>webpack</category>
      <category>npm</category>
    </item>
  </channel>
</rss>
