Crazylife

Crazylife

Member Since 1 Year Ago

Experience Points 8,560
Experience
Level
Lessons Completed 2
Lessons
Completed
Best Reply Awards 0
Best Answer
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.

25 Oct
1 month 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
1 month 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
1 month 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
2 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
3 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
3 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
4 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
4 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
4 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
4 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
4 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
5 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
5 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
5 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
5 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
5 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
5 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
5 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?

17 Jun
5 months ago

Crazylife left a reply on When Render A View, Will It Run The Javascript As Well?

@topvillas But function inside tag will be generated right?

Crazylife started a new conversation When Render A View, Will It Run The Javascript As Well?

When rendering a view, will javascript of that view run also? For example

MyController.php

$view = View::make('pages.preview')->render();

// I will not display the preview.blade.php, i want it run some of the javascript function when i call it. Will the function of javascript be triggered?

14 Jun
5 months ago

Crazylife left a reply on What Package Can I Use To Convert Html To Pdf Or Image?

@pardeepkumar Actually i want to do it at backend by convert the view into image or pdf instead of using jquery etc to do it.

Crazylife left a reply on What Package Can I Use To Convert Html To Pdf Or Image?

@pardeepkumar I have no idea why i am getting class dompdf.wrapper doesnt exist error.

Crazylife started a new conversation What Package Can I Use To Convert Html To Pdf Or Image?

I tried dompdf and phantom magick, all gaves me error. For dompdf, return me class dompdf.wrapper doesnt exist, while phantom magick return the binary error. i am using laravel 5.3 with php 5.6, is there any package i can use to convert html to pdf or image? thanks.

09 Jun
6 months ago

Crazylife left a reply on How To Write The Eloquent For Sql Where The FROM Clause Consist Of Table And Select Statment

@PercyMamedy ok, can i ask if using query builder then i have 2 @set variable, i just call DB::statement two times?

DB::statement(DB::raw('SET @row_number:=0;'));
DB::statement(DB::raw('SET @ids:="";'));

Crazylife started a new conversation How To Write The Eloquent For Sql Where The FROM Clause Consist Of Table And Select Statment

SELECT @row_number:=CASE WHEN @id_category=id_category THEN @row_number+1 ELSE 1 END AS row_number,@id_category:=id_category AS id_category
FROM products, (SELECT @row_number:=0,@id_category:='') AS test  
ORDER BY `id_category` 

How can i transform this sql raw query by using eloquent method? No idea on how to write it in eloquent way for this statement

FROM products, (SELECT @row_number:=0,@id_category:='')

Thanks.

07 Jun
6 months ago

Crazylife started a new conversation How To Make A Portion Of Js Inside A Function Usable And Able To Be Called In Multi View?

I have a portion of code which need to be reused for multi view. And currently, i created a directories called js in my pages, and a blade.php inside js folder.

//details.blade.php inside js folder

............................ // any related code

i simply throw the code inside the details.blade.php. After that in my view, script function i will include this blade.


function($args1,$args2){
@include(js.details)
...... and other code here.
}

I think this is not the correct way to do it, am i right? How you guys manage it?

ps: i am not reusing the function but only some of the code which the function contain.

06 Jun
6 months ago

Crazylife left a reply on How To Pass The Variable Returned From Another Controller To The View In Another Controller?

@tykus Ok, thanks. I am willing to try out too, if you have a better suggestion on this.

Crazylife left a reply on How To Pass The Variable Returned From Another Controller To The View In Another Controller?

Is it right way to do it if i return the view by controlling the condition and in the controller i want just return $this->test(); ?

Crazylife left a reply on How To Pass The Variable Returned From Another Controller To The View In Another Controller?

So if the test() variable consist of array and single value, how can i return the variable data and pass to the view? As i know i can return it in array form and getTest() will get the array variable and pass to view?

Crazylife left a reply on How To Pass The Variable Returned From Another Controller To The View In Another Controller?

@tykus I am doing something like this

//class Controller2 extends Controller

public function test(){
$varA = Model::where(...)->get();
$varB = Model2::where(...)->get();
$varC = Model3::where(...)->get();
}

//class Controller extends BaseController

public function getTest(){
return View::make('......', compact('varA','varB','varC'));
}

This is not correct?

Crazylife started a new conversation How To Pass The Variable Returned From Another Controller To The View In Another Controller?

I want to pass multiple variable get from the function in controller2 and return to view in controller1. How can i make it?

Controller1 extended controller2, i want to return multiple variable get from controller2 and return to controller1 view.