Crazylife

Crazylife

Member Since 2 Years Ago

Experience Points 9,640
Experience Level 2

360 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-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.

17 Jul
3 days ago

Crazylife left a reply on How To Get A Specific Categories With Its Sub Categories Item?

yes, id category is primary. But with this way how do i get the id_category in subcategories? As what i know

$mc = Category::with('subcategories.subcategories')->where('category_name',  $category_name)->first();

//get all subcategories
dd($mc->subcategories);

Crazylife left a reply on How To Get A Specific Categories With Its Sub Categories Item?

Let's say i have 3 level, when i choose level 1, i need to get level 2 and level 3 id_category. If I choose level 2 then i will get level 2 and level 3 id_category.

Category::with('subcategories')->where('category_name',  $category_name)->get();

This only return level 2 categories, when choose level 1.

Crazylife left a reply on How To Get A Specific Categories With Its Sub Categories Item?

I am doing like this

Category::with('subcategories')->where('category_name',  $category_name)->get();

But it returned me 1 result only

Crazylife left a reply on How To Get A Specific Categories With Its Sub Categories Item?

This returned me all the main categories.

16 Jul
4 days ago

Crazylife started a new conversation How To Get A Specific Categories With Its Sub Categories Item?

I have this relationship in my model

public function subcategories() {
    return $this->hasMany(self::class, 'id_parent', 'id_category');
}

Let's say i have Fruit as my main parent, sub is frozen and fresh.

When user select fruit, i want to display frozen and fresh item too.

How can i do this in easy way instead of create multiple statement to get all of the id category?

13 Jul
1 week ago

Crazylife left a reply on Generate Unique Payment Reference Number

My id order will only create after payment made. Before that, will need a reference no assign to multiple id order for different vendor to show it is under same transaction.

Crazylife left a reply on Generate Unique Payment Reference Number

Yes, can include user id. But i want to make it like in 15 INT. Id user will keep increasing.

12 Jul
1 week ago

Crazylife left a reply on Generate Unique Payment Reference Number

Do you mean using separate table for each user? or a table called transaction?

Crazylife started a new conversation Generate Unique Payment Reference Number

How can i generate unique payment reference number for each user?

Currently i am using prefix year month then increment sequence. E.g. 190700001

I am doing it in this way

Order::orderBy('created_at', 'desc')->first();

I found this will caused duplicate reference number when 2 user clicked on the same time when doing payment.

Any solution to solve this issue? I want the reference number in same length. Thanks.

19 Jun
1 month ago

Crazylife started a new conversation How To Create Scheduling Task Dynamically?

For my case, how to update status of an order after 24 hours from created at date time.

E.g. i have 2 orders being placed at 1.00pm and 3.00pm. I want the order status auto update next day 1.00pm and 3.00pm.

How to make the task execute on the time only when necessary? What kind of method being used for this circumstances?

Looking for advice and suggestions, thanks.

09 Jun
1 month ago

Crazylife started a new conversation Cross Database Relationship With Eloquent

How to set up the database connection to allow cross database with eloquent method?

For example, I have table A and table B.

My table A model

 public function branch()
   
    {
        return $this->belongsTo('App\Models\tableA', 'id');
    }

I wrote a query

$query = tableA::on('second_db')->get();


// looping result in blade

@foreach($query as $q)
{{ $q->branch->name }}
@endforeach

I found that the branch doesn't has any connection with it. How can i make this work?

27 May
1 month ago

Crazylife left a reply on How To Match Word From Beginning Until A Space In A Query To Get Result?

@SNAPEY - Let's say if i have some value like "tesco store", "product tesco", "A4 tesco paper", and so on.

If i search by "tes", no result will be returned. It must enter a full word like "tesco" to return "tesco store". I no want to return other value like "product tesco", "A4 tesco paper".

At the moment. i am using this way result will not be displayed when search by "tesco store"

$model->where(DB::raw("substr(name, 1, instr(name, ' ') - 1)", 'like' , "$term %")->get()`

Expected result

$term = 'tesco'; // return "tesco store"
$term = 'tesco store'; //return "tesco store"
$term = 'tes'; // return nothing
$term = 'tesco s'; // return nothing
$term = 'te'; //return nothing

Crazylife left a reply on How To Match Word From Beginning Until A Space In A Query To Get Result?

@SNAPEY - For example, my database stored multiple value such as tesco store, product tesco, A4 tesco paper, and so on.

When i entered tesco, only tesco store will be returned. I want the search from beginning of the string, so product tesco, A4 tesco paper will not be returned for my case.

Next example, when i entered "tesco s", tesco store will not be returned too, it must be fully match the word like "tesco store" only return result.

Crazylife started a new conversation How To Match Word From Beginning Until A Space In A Query To Get Result?

How to query a record where need to match word from beginning until a space?

For example, i have entered full keyword "tesco" then in my database consist of "tesco store". I would like to return this result.

If keyword "tes" entered, i will not show any record even there's partial string match with it.

I cannot use LIKE % % for it. Any method can achieve it?

17 May
2 months ago

Crazylife started a new conversation (500) Internal Server Error Ipay88 Payment Gateway Integration

I have set the backendURL to https://testing.com/backend_response

using POST method for my (backend_response) route.

BackendURL need to return with the Response Data as "200" and the Response Data as "RECEIVEOK" to acknowledge that the payment status has been received.

In my controller, i already did as below


public function test() {
// some staatus code here
  return response()->setStatusCode(200, "RECEIVEOK");
}

May i know is this they way to return the response to the ipay88?

16 May
2 months ago

Crazylife left a reply on Laravel Csrf Token Mismatch In POST Request With URL

@PHPHUPPTECHNOLOGIES - Thanks for the reply, I already figured it and working fine !

15 May
2 months ago

Crazylife left a reply on Laravel Csrf Token Mismatch In POST Request With URL

@TOKOIWESLEY - I tried to exclude using your way

protected $except = [
        'response',
    ];

But still return me token mismatch, will it affected if any prefix in front of the response? E.g. www.test.com/my/response

Crazylife left a reply on Laravel Csrf Token Mismatch In POST Request With URL

@TOKOIWESLEY - I can't use blade, because i set the url for payment gateway response.

Crazylife started a new conversation Laravel Csrf Token Mismatch In POST Request With URL

I am getting token mismatch when i call to a url www.test.com/response

In my web.php

  Route::post("response", '[email protected]');

I am getting token mismatch because i didnt pass any crsf_token to it. How to solve this issue?

24 Apr
2 months ago

Crazylife started a new conversation Ipay88 Payment Gateway Integration

Anyone had tried integrate ipay88 payment gateway? Is there any package can be used like paypal?

23 Apr
2 months ago

Crazylife started a new conversation How Do E-commerce Orders Process Work When Checkout?

May i know is the purchase order being created when customer clicked on checkout before payment made? The created purchase order payment status will be set to unpaid and pending the payment. And also the purchase order will be cancelled after a certain period if status still remain unpaid.

Is this how it works for e-commerce?

21 Apr
2 months ago

Crazylife started a new conversation How To Limit The Link Of Pagination To Be Displayed?

I want to show less page link for the pagination, by default it looks like

< 1 2 3 4 5 6 7 8 ... 100 101 >
< 1 2 ... 8 9 10 11 12 13 14 ... 100 101 >

How can i make it in this way?

< 1 2 3 4 5 ... 101 >
< 1 ... 8 9 10 11 ...101 >

This is my code

@if ($paginator->hasPages())
    <ul class="pagination">
        {{-- Previous Page Link --}}
        @if ($paginator->onFirstPage())
            <li class="page-item disabled"><span class="page-link">&laquo;</span></li>
        @else
            <li class="page-item"><a class="page-link" href="{{ $paginator->previousPageUrl() }}" rel="prev">&laquo;</a></li>
        @endif

        {{-- Pagination Elements --}}
        @foreach ($elements as $element)
            {{-- "Three Dots" Separator --}}
            @if (is_string($element))
                <li class="page-item disabled"><span class="page-link">{{ $element }}</span></li>
            @endif

            {{-- Array Of Links --}}
            @if (is_array($element))
                @foreach ($element as $page => $url)
                    @if ($page == $paginator->currentPage())
                        <li class="page-item active"><span class="page-link">{{ $page }}</span></li>
                    @else
                        <li class="page-item"><a class="page-link" href="{{ $url }}">{{ $page }}</a></li>
                    @endif
                @endforeach
            @endif
        @endforeach

        {{-- Next Page Link --}}
        @if ($paginator->hasMorePages())
            <li class="page-item"><a class="page-link" href="{{ $paginator->nextPageUrl() }}" rel="next">&raquo;</a></li>
        @else
            <li class="page-item disabled"><span class="page-link">&raquo;</span></li>
        @endif
    </ul>
@endif

How can i achieve the desired output as i stated? Thanks.

19 Apr
3 months ago
18 Apr
3 months ago

Crazylife started a new conversation How To Set Persistent Database Connection For Different User From Different Country Login?

I have tried to use middleware, e.g.

 $country  = $request->route()->parameter('country');

        DB::disconnect();
        Config::set('database.default','test_'.$country);
        DB::reconnect();

//my route
Route::group([
    'prefix' => '{country}',
    'middleware' => 'locale'
], function() {
.....
  Route::group(['prefix' => 'user'], function () {
Auth::route();
......
    });
    });

It works for register and login, but failed for others like view user account...etc.

May i know what's wrong with this?

I am trying to set up 1 database for 1 country. Should i just set it in app service provider using request::segment and config set my database?

10 Apr
3 months ago

Crazylife started a new conversation Best Practice Url And Route Design For Multilingual Website Using Subfolder Instead Of Sub Domain

I have a question about when design a multi language and country website url.

I am using subfolder inside my main folder instead of subdomain when implement the system. In my system, i allow them to select language and the country site.

For example, if i am select english as my language and a country then the url as belows

/subfolder/en/country_code/index

My route looks like

Route::group(['prefix' => 'test/{language}/{county_code}'], function () {
  
});

Should i open multiple subfolder for each country? Or i can maintain one subfolder and connect to multiple database based on country?

Any advice on doing this? Thanks.

21 Feb
4 months 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
5 months 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
5 months 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
5 months 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
7 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
7 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
8 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
8 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
9 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
9 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
10 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
11 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
11 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?