Crazylife

Crazylife

Member Since 1 Year Ago

Experience Points 8,890
Experience Level 2

1,110 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 2
Lessons
Completed
Best Reply Awards 0
Best Reply
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.

21 Feb
1 month ago

Crazylife started a new conversation How To Get Record In Between Range Of Quantity?

I have records as shown below

    id | min | max
    1       5   15
    2       15  null

For example, my query

$test = test::where('max' , '>=', 10)->where('min' , '<=', 10)->get();

This result return me null collection.

The 'max' null as infinity. How can i make it like if i put 10 then it will return result id = 1 for me. if put 16 then will return id = 2?

17 Feb
1 month ago

Crazylife left a reply on Unit Converter For Product

@SNAPEY - ya, right. Do i need attribute like parent id to know which is the biggest and smallest unit? E.g. Carton -> Box -> pcs

Crazylife left a reply on Unit Converter For Product

@SNAPEY - Because i am storing only conversion rate to base. But i didnt store conversion between box and carton. I only know carton = how many pcs and box = how many pcs

Crazylife left a reply on Unit Converter For Product

@SNAPEY - For example, pcs is always my base unit for conversion. But during display, will show 1carton = 10box = 100pcs

Crazylife started a new conversation Unit Converter For Product

I have a question regarding to unit converter for product. I stored the following data as shown below

1 PCS  = 1 PCS
1 BOX = 10 PCS
1 CARTON = 40 PCS

database design

id | fromUnit | ratio | toUnit

How should i design my database so that i know 1 BOX = ? CARTON? E.g 2 BOX = 0.5 CARTON. (Formula : 20/40 = 0.5)

15 Feb
1 month ago

Crazylife left a reply on Suggestion On Database Design For Storing Product With Bulk Purchase Price

@ARTCORE - Not sure if i am getting it right. Based on the table(product_bulk_price) i created, it serves as a condition rule table, just make some changes on it.

E.g.

Product_bulk_price (product_discount)
----------------------------
id_price    | id_product    | min_qty   | max_qty   | price_type        | price
1           1           20          null            discount        10      

if quantity && discount is a rule, then i will apply 10% on the retail unit price.

Instead of storing the unit price in same table with the rule, but create a discount table to store the condition rule.

Sorry, if i am getting it wrong. Just first time implement this, need take time to go through. hehe

Crazylife left a reply on Suggestion On Database Design For Storing Product With Bulk Purchase Price

@ARTCORE - Mind to show some sample? I am having some price like retail price (applied while less than qty rule purchased) and wholesale price (applied when reached certain qty purchased).

Crazylife started a new conversation Best Database Design For Storing Product With Multiple Price

I am designing a database which able to store multiple price for each product. Is there any flaw for the design below?

Product
-----------
id_product| name            | uom | active | ...
1                 | product A     | bag  | 1          |...

Product_bulk_price
----------------------------
id_price  | id_product  | min_qty    | max_qty           | unit_price
1              | 1                   |10              | 29                       | 10
2              | 1                   | 30             | null                     | 8
....so on

My case want to store multiple price of the product. Each product will be given different price when hit the quantity as stated. If qty fall 10-29 then price = 10, else 30 or more price = 8.

I will do calculation based on user order quantity and sum it.

Is there any better solution or any suggestion? Am i on the right track?

30 Jan
1 month ago

Crazylife left a reply on Extends Blade File From Layouts Directory Caused Syntax Error

@MANELGAVALDA - Sorry, i found the error because of missing ' while extends haha.

Crazylife started a new conversation Extends Blade File From Layouts Directory Caused Syntax Error

I have 2 blade file in my layouts directory

-master.blade.php
-page.blade.php

My page.blade.php will extends master.

In my pages directory, i created an index page, and then extends to layouts.page. When i run it it throws me synxtax error.

syntax error, unexpected '__data' (T_STRING)

When i removed the extends in page.blade.php. Then it works. Anything wrong with it?

17 Dec
3 months ago

Crazylife left a reply on How To Bcc To Sender Mail?

@SIANGBOON - i am using this way

 $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl');
            $transport->setUsername('[email protected]');
            $transport->setPassword('123456');
            $gmail = new Swift_Mailer($transport);
            Mail::setSwiftMailer($gmail);

Mail::send('emails.user.registered', function($m) use ($email, $subject) {
                $m->to($email)
                  ->bcc('[email protected]','System Mailer')
                  ->subject($subject)
            });

I am doing it in this way, but not working.

16 Dec
3 months ago

Crazylife left a reply on How To Bcc To Sender Mail?

@SIANGBOON - Let's say, i am using [email protected] as my sender, i sent to [email protected] and bcc back to [email protected] It is not working when sender and bcc same email address.

Crazylife started a new conversation How To Bcc To Sender Mail?

I tried to keep a copy of mail content by bcc to sender mail but it doesn't work. Is there a way to keep a copy to what sender sent?

25 Oct
4 months ago

Crazylife left a reply on Calculation For Stock Expiry Date

@Vilfago if using your way, i think need to add some other calculation to get the difference day, am i right? When manufacture_date = 2018-10-21, shelf life = 7 then my expiry date will be 2018-10-27. If today date 2018-10-25, follow your method it will return 1 day. By right, the difference should be 2 days? Correct me if i am wrong.

Crazylife left a reply on Calculation For Stock Expiry Date

@Vilfago Yes, but this will return positive all the time, i want to detect whether it is expired or not instead of just different of day.

24 Oct
4 months ago

Crazylife started a new conversation Calculation For Stock Expiration Date

Check Product A expiry date:

$manufacturer_date = "2018-10-21";
$expiry_day =  7;
$expiry_date = Carbon::parse($manufacturer_date)->addDays(($expiry_day - 1))->format('Y-m-d'); // 2018-10-27

Here i calculate the difference between expiry date and today date.

// expiry date - today date
$today = strtotime(Carbon::now()->format('Y-m-d'));
$expiry = strtotime(expiry_date);
$diff_day = (int)floor(($expiry-$today)/(60*60*24));

if day difference less than zero meaning all considered as expired. Am i doing in correct way for calculation?

17 Oct
5 months ago

Crazylife left a reply on Is There Possible To Make A File Import All Class Model, And Then Share It To Multiple Controller?

Just curious, because keep declaring same class over the other controller, will left out sometime. So want to make it like global, so i can just use it everywhere.

Crazylife started a new conversation Is There Possible To Make A File Import All Class Model, And Then Share It To Multiple Controller?

I want to make this to global which can share among controller/

use App\Models\ModelName;

Possible to do it or every controller can only has its own imports/aliases?

03 Oct
5 months ago

Crazylife started a new conversation How To Convert Date To Timezone?

I want to convert my created_at date, i do something like this but got error

 Model::whereDate(DB::raw("(CONVERT_TZ(created_at, +5:00, +8:00))"), '=>', $start)->whereDate(DB::raw("(CONVERT_TZ(created_at, +5:00, +8:00))"), '<=', $end)......
        

I tried but i gave me error, is there anyway can convert timezone using eloquent model?

10 Sep
6 months ago

Crazylife left a reply on How To Create From Format With Timezone Using Carbon?

@pardeepkumar I am getting the file format from integration, they will pass me a format like GMT+8 or GMT+0800, how can i store the datetime in my database?

Crazylife started a new conversation How To Create From Format With Timezone Using Carbon?

I have a string

$string = "180711000000GMT+0800"

// try to convert it 
Carbon::createFromFormat('YmdHisTO', $string)->format...

It shows me this error.

Unexpected data found.
The timezone could not be found in the database
Data missing

How can i convert the datetime if there's GMT+0800 behind of the string?

20 Aug
7 months ago

Crazylife started a new conversation How To Set Sidebar Menu To Restrict Other Role User To See The Sidebar Menu?

I am using jeroennoten/Laravel-AdminLTE. In adminlte.php, i create a menu

        [
                    'text' => 'Testing',
                    'url' => 'test',
                    'icon' => 'store',             
                    'can' => 'testing',
                ],

I have created middleware named 'testing', but it doesn't work, not appear on the side menu bar. Anything i am doing wrong?

09 Aug
7 months ago

Crazylife started a new conversation How To Use Other Font Awesome In Jeroennoten/Laravel-AdminLTE Package?

I am using font awesome version 4.7, but i found there's some other icon available in font awesome version 5.2. How can i call the font awesome version 5.2 and use it in my /config/adminlte.php? Is there any solution?

01 Aug
7 months ago

Crazylife started a new conversation How To Read Content Of Sftp Text File Line By Line And Save Into Database?

I get the file content using through the server

Storage::disk('sftp')->get($k);

ps: $k is the path of the txt file in server.

This will return

No.|Desc|Qty|
1|abc|1|
2|efg|2|
3|hhh|3|

How can i read this content line by line and save to database?

Crazylife left a reply on How To Cut All The File From A Directory From Sftp Server To Local Server Using File System?

@lostdreamer_nl Meaan that after loop and save the folder and then just call delete() function to delete related file right?

Crazylife started a new conversation How To Cut All The File From A Directory From Sftp Server To Local Server Using File System?

I have a server used to store exchange file.

/uploads/a.txt
/uploads/b.txt
....so on

I am using this to get all of the file inside /uploads/ dir.

  $list = Storage::disk('sftp')->allfiles();

After that, i use foreach to loop every file based on directory to my local.

 Storage::disk('save')->put($old,$new);

Right now i only able to save the file to local without cleaning the /uploads/ dir, and not sure is this practical way to do it. Can i know how can i cut all the file from the sftp /uploads/ dir and store to my local?

27 Jul
7 months ago

Crazylife left a reply on How To Translate Language Of Apps Based On Json Language File?

@bobbybouwmann i got this problem after using double _

Call to undefined function __()
26 Jul
7 months ago

Crazylife started a new conversation How To Translate Language Of Apps Based On Json Language File?

I have a json file consist of this data

{
  "_comment": "https://cdn.datatables.net/plug-ins/9dcbecd42ad/i18n/English.json",
  "sEmptyTable":     "No data available in table",
  "sInfo":           "Showing _START_ to _END_ of _TOTAL_ entries",
  "sInfoEmpty":      "Showing 0 to 0 of 0 entries",
  "sInfoFiltered":   "(filtered from _MAX_ total entries)",
  "sInfoPostFix":    "",
  "sInfoThousands":  ",",
  "sLengthMenu":     "Show _MENU_ entries",
  "sLoadingRecords": "Loading...",
  "sProcessing":     "Processing...",
  "sSearch":         "Search:",
  "sZeroRecords":    "No matching records found",
  "oPaginate": {
    "sFirst":    "First",
    "sLast":     "Last",
    "sNext":     "Next",
    "sPrevious": "Previous"
  },
  "oAria": {
    "sSortAscending":  ": activate to sort column ascending",
    "sSortDescending": ": activate to sort column descending"
  }
}

I tried with

trans('datatable.sInfo')
_('datatable.sInfo')

but it returns datatable.sInfo for me. What's wrong or i can only translate this with array not json?

14 Jul
8 months ago

Crazylife left a reply on How To Set Locale Based On The Language Stored In Database?

@lostdreamer_nl I created a class in middleware folder as setLocale.php, and added the class to web in kernel.php. But i can't get the user id. I am not using any session, is there anything i missing that caused the Auth::user() returning null?

Crazylife left a reply on How Can I Get The The Url Of File Inside The Resources Folder?

@lostdreamer_nl The only way to access resources folder is write a route function to get whatever i need right?

Crazylife started a new conversation How Can I Get The The Url Of File Inside The Resources Folder?

I want to get the file inside the resources folder, how can i get it?

i tried asset(), but it keeps show me error 404 not found. Is it i can't do it like how i access the public folder?

asset('resources/test')

Crazylife started a new conversation How To Set Locale Based On The Language Stored In Database?

I tried to set locale by getting the language stored in database for a user, but it always return null value for user().

class SetLocale
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        dd($request->user()); // return null
      //  app()->setLocale('');

        return $next($request);
    }
}

In kernel.php

'web' => [
            \App\Http\Middleware\SetLocale::class,
]

Is there anything wrong with my step?

12 Jul
8 months ago

Crazylife started a new conversation How To Allow User To View Only And Restrict User Perform Action In Certain Page?

I am seeking for advice on how to setup for a user to view only or perform action on certain page. For example, user A can perform action by clicking button on certain page, while user B only allow to view without performing any action. How do you guys handle for the user, if there's user same role but different permission?

Crazylife left a reply on Anyone Facing Barcode Generator Using Milon/barcode Package Got Issue When Displaying?

@toby I tried {!! DNS1D::getBarcodeSVG('123', "C39", 1, 25, '#2A3239') !!} , it worked for me, hehe. The last 3 params is width height and color right?

Crazylife left a reply on Anyone Facing Barcode Generator Using Milon/barcode Package Got Issue When Displaying?

@toby I always having the issue during printing, the barcode always show nothing only the border, i need to close it and print again then it only will appear.

Crazylife started a new conversation Anyone Facing Barcode Generator Using Milon/barcode Package Got Issue When Displaying?

I tried to generate barcode using milon/barcode package, but every first time i generate it shows me blank barcode. Anyone facing same issue as well?

07 Jul
8 months ago

Crazylife left a reply on How To Set Different Language For A Defined Variable?

@BishoyWagih Right now, i just need to translate some messages instead of the web application.

Crazylife started a new conversation How To Set Different Language For A Defined Variable?

I am going to translate message content in different language based on user. In my controller, i have return the message content. For example,

$msg = "Request From :" .$name;
$msg.= "Date :".$date;

return $msg;

I know it can simply use if else statement, but if the language grow big will caused the function very long. How to handle this? How can i translate the Request From and Date into different language?

04 Jul
8 months ago

Crazylife started a new conversation How To Print A Html Content Using Label Printer?

I want to print html content using label printer, anyone got similar example to show how to make it? I tried mine, the second page always not in correct alignment will be cut off.

28 Jun
8 months ago

Crazylife started a new conversation How To Do Grouping Based On Column When Create Excel Using Laravel Maatwebsite?

Is there any function in laravel maatwebsite excel allow to do grouping and subtotal based on column details?

23 Jun
9 months ago

Crazylife left a reply on How To Select From Subquery Using Eloquent?

This is what i had done

$sub = SalesTable::select(DB::raw('field1,field3,SUM(field2)as total'))         
              ->groupBy('field1',DB::raw('field3 having total<> 0'));   

 $main = DB::table(DB::raw("({$sub->toSql()}) as sub") )
            ->select('field1', 'field3','total');
            $main ->mergeBindings($sub_breakdown->getQuery());
            $main ->groupBy('field1');       
            $main ->get();

And dd($main) return me this

Builder {#2361 ▼
  #connection: MySqlConnection {#2148 ▶}
  #grammar: MySqlGrammar {#2149 ▶}
  #processor: MySqlProcessor {#2150}
  #bindings: array:6 [▶]
  +aggregate: null
  +columns: array:2 [▶]
  +distinct: false
  +from: Expression {#2364 ▶}
  +joins: null
  +wheres: null
  +groups: array:1 [▶]
  +havings: null
  +orders: null
  +limit: null
  +offset: null
  +unions: null
  +unionLimit: null
  +unionOffset: null
  +unionOrders: null
  +lock: null
  #backups: []
  #bindingBackups: []
  #operators: array:29 [▶]
  #useWritePdo: false
}

I am not sure it is working or not, but i cant get my result although there is no error.

Crazylife started a new conversation How To Select From Subquery Using Eloquent?

I am using laravel 5.3. I want to achieve something like this using eloquent.

select field1, field2
from (select field1, field3, sum(field2) as total
      from sales
      group by field1, field2
      having total <> 0
     ) s
group by field1;

How can i do this using eloquent?

21 Jun
9 months ago

Crazylife left a reply on How To Get The Sum Quantity Of Stock Available For Each Franchise Based On Stock Transaction?

@bobbybouwmann yeah, i can write in my controller. But, no idea how to start it in controller at this moment.

Crazylife left a reply on How To Get The Sum Quantity Of Stock Available For Each Franchise Based On Stock Transaction?

@bobbybouwmann i can get the result i want calling model in view, but will caused performance issue, so i prefer not to use it. Finding a way to do this i think will be better.

Crazylife left a reply on How To Get The Sum Quantity Of Stock Available For Each Franchise Based On Stock Transaction?

@bobbybouwmann

$ad = MenuCatalog::leftJoin('transaction', function ($join){
            $join->on('transaction.id_franchise','=','menucatalog.id_franchise')
                ->on('transaction.id_item','=','menucatalog.id_item');
          
        })->whereIn('id_franchise',$options)
            ->select('id_item',
                DB::raw('( SUM(CASE type WHEN 1 THEN format(stock_in,4) ELSE format(stock_out,4) * - 1 END) ) as qty'))
            ->groupBy('id_item')->get();

This is what i tried so far. How can i sum it for each branch and show in column.

Crazylife started a new conversation How To Get The Sum Quantity Of Stock Available For Each Franchise Based On Stock Transaction?

I need to get the total qty available for each franchise based on per item.

I have menu_catalog table which will link to main table of franchise and item table.

id   id_franchise   id_item
1     1                         1
2    1                         2
3    1                         3
4    2                        1
5    2                        3
6    3                        2

Each of the franchise might contain different items.

For the stock_transaction table

id  id_franchise  id_item  stock_in  stock_out  type  unit_price
1    1                        1               10                                  1         5.00
2   1                        1                                 2                  2         5.00
3   2                       3               10                                  1         3.00

// type : 1 = stock in while 2 = stock out

Expected output :

id_item franchise1 franchise2 franchise3
1              8,40            0,0              0,0
2             0,0               0,0              0,0
3             0,0               10,30           0,0

I have a condition, when type = 1 then SUM the stock_in else SUM stock_out * -1, same for the price. I will store the total qty and total price for each item based on franchise.

I will select all item belong to this 3 franchises, even some item not existed on their menu catalog. The item not belong to the franchise will be return as 0.

How can i do this?

20 Jun
9 months ago

Crazylife started a new conversation How To Use Eloquent To Get Data From Database If The Table Have A Prefix Value?

How to access the database using eloquent way if i have a table with prefix value to determine belong to which user? For example, user A will access to A_table while user B will access to B_table. Inside table all field are same, just different data stored based on user. How can i create a model which allow me to build query using eloquent way instead of query builder? How to differentiate which user access to which database?