LadyDeathKZN

Member Since 2 Years Ago

Experience Points
4,080
Total
Experience

920 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
5
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.

  • Community Pillar

    Earned once your experience points ranks in the top 10 of all Laracasts users.

Level 1
4,080 XP
Apr
16
1 month ago
Activity icon

Started a new Conversation Pure PHP To Laravel Conversion Help

Hi everyone, would someone be willing to help me convert this code into Laravel? I have changed the few things I do recognize but the prepare and bind_params are not working/ I have managed to get it to the point of the bind_params then nothing works. I have returned the code to how it was after 3 days of frustration and I am sure there is a simplier way to do this.

public function registration()
    {
        if (isset($_POST["email"]) && isset($_POST["username"]) && isset($_POST["password1"]) && isset($_POST["password2"])) {
            $errors = array();

            $emailMaxLength = 254;
            $usernameMaxLength = 20;
            $usernameMinLength = 3;
            $passwordMaxLength = 19;
            $passwordMinLength = 5;

            $email = strtolower($_POST["email"]);
            $username = $_POST["username"];
            $password1 = $_POST["password1"];
            $password2 = $_POST["password2"];

            //Validate email
            if (preg_match('/\s/', $email)) {
                $errors[] = "Email can't have spaces";
            } else {
                if (!$this->validate_email_address($email)) {
                    $errors[] = "Invalid email";
                } else {
                    if (strlen($email) > $emailMaxLength) {
                        $errors[] = "Email is too long, must be equal or under " . strval($emailMaxLength) . " characters";
                    }
                }
            }

            //Validate username
            if (strlen($username) > $usernameMaxLength || strlen($username) < $usernameMinLength) {
                $errors[] = "Incorrect username length, must be between " . strval($usernameMinLength) . " and " . strval($usernameMaxLength) . " characters";
            } else {
                if (!ctype_alnum($username)) {
                    $errors[] = "Username must be alphanumeric";
                }
            }

            //Validate password
            if ($password1 != $password2) {
                $errors[] = "Passwords do not match";
            } else {
                if (preg_match('/\s/', $password1)) {
                    $errors[] = "Password can't have spaces";
                } else {
                    if (strlen($password1) > $passwordMaxLength || strlen($password1) < $passwordMinLength) {
                        $errors[] = "Incorrect password length, must be between " . strval($passwordMinLength) . " and " . strval($passwordMaxLength) . " characters";
                    } else {
                        if (!preg_match('/[A-Za-z]/', $password1) || !preg_match('/[0-9]/', $password1)) {
                            $errors[] = "Password must contain atleast 1 letter and 1 number";
                        }
                    }
                }
            }

            //Check if there is user already registered with the same email or username
            if (count($errors) == 0) {
                //Connect to database
                require dirname(__FILE__) . '/database.php';

                if ($stmt = $mysqli_conection->prepare("SELECT username, email FROM sc_users WHERE email = ? OR username = ? LIMIT 1")) {

                    /* bind parameters for markers */
                    $stmt->bind_param('ss', $email, $username);

                    /* execute query */
                    if ($stmt->execute()) {

                        /* store result */
                        $stmt->store_result();

                        if ($stmt->num_rows > 0) {

                            /* bind result variables */
                            $stmt->bind_result($username_tmp, $email_tmp);

                            /* fetch value */
                            $stmt->fetch();

                            if ($email_tmp == $email) {
                                $errors[] = "User with this email already exist.";
                            } else if ($username_tmp == $username) {
                                $errors[] = "User with this name already exist.";
                            }
                        }

                        /* close statement */
                        $stmt->close();
                    } else {
                        $errors[] = "Something went wrong, please try again.";
                    }
                } else {
                    $errors[] = "Something went wrong, please try again.";
                }
            }

            //Finalize registration
            if (count($errors) == 0) {
                $hashedPassword = password_hash($password1, PASSWORD_BCRYPT);
                if ($stmt = $mysqli_conection->prepare("INSERT INTO sc_users (username, email, password) VALUES(?, ?, ?)")) {

                    /* bind parameters for markers */
                    $stmt->bind_param('sss', $username, $email, $hashedPassword);

                    /* execute query */
                    if ($stmt->execute()) {

                        /* close statement */
                        $stmt->close();
                    } else {
                        $errors[] = "Something went wrong, please try again.";
                    }
                } else {
                    $errors[] = "Something went wrong, please try again.";
                }
            }

            if (count($errors) > 0) {
                echo $errors[0];
            } else {
                echo "Success";
            }
        } else {
            echo "Missing data";
        }
    }

    public function login()
    {
        if (isset($_POST["email"]) && isset($_POST["password"])) {
            $errors = array();

            $email = $_POST["email"];
            $password = $_POST["password"];

            //Connect to database
            require dirname(__FILE__) . '/database.php';

            if ($stmt = $mysqli_conection->prepare("SELECT username, email, password FROM sc_users WHERE email = ? LIMIT 1")) {

                /* bind parameters for markers */
                $stmt->bind_param('s', $email);

                /* execute query */
                if ($stmt->execute()) {

                    /* store result */
                    $stmt->store_result();

                    if ($stmt->num_rows > 0) {
                        /* bind result variables */
                        $stmt->bind_result($username_tmp, $email_tmp, $password_hash);

                        /* fetch value */
                        $stmt->fetch();

                        if (password_verify($password, $password_hash)) {
                            echo "Success" . "|" . $username_tmp . "|" .  $email_tmp;

                            return;
                        } else {
                            $errors[] = "Wrong email or password.";
                        }
                    } else {
                        $errors[] = "Wrong email or password.";
                    }

                    /* close statement */
                    $stmt->close();
                } else {
                    $errors[] = "Something went wrong, please try again.";
                }
            } else {
                $errors[] = "Something went wrong, please try again.";
            }

            if (count($errors) > 0) {
                echo $errors[0];
            }
        } else {
            echo "Missing data";
        }
    }

    public function validate_email_address($email)
    {
        return preg_match('/^([a-z0-9!#$%&\'*+-\/=?^_`{|}~.][email protected][a-z0-9.-]+\.[a-z0-9]+)$/i', $email);
    }
Jan
24
3 months ago
Activity icon

Replied to Drag And Drop Form Builder Like Gravity Forms From WordPress

It would be easier yes, but the person that will be using this application has no coding knowledge and the forms need to be edited now and again.

Jan
22
3 months ago
Activity icon

Started a new Conversation Drag And Drop Form Builder Like Gravity Forms From WordPress

Hi all, Is there any drag and drop form builder that is very similar to the Gravity Form plugin in WordPress? That is supported with Laravel 8? I have found a few but they are so old.

Dec
08
5 months ago
Activity icon

Replied to Data Ranges Between Records Using Carbon

Hi, thank you for the reply, I am getting this error:

Method Illuminate\Database\Eloquent\Collection::latest does not exist. 
Dec
07
5 months ago
Activity icon

Started a new Conversation Data Ranges Between Records Using Carbon

Hi everyone, I hope that you all been keeping well during this time.

I am busy developing a reporting application. I have 2 test records in the database: 1 - 2020-12-06 07:01:16 2 - 2020-12-07 14:55:12

The reporting Modal has the following info:

Report Preferences - will generate a PDF Report Daily - Specific Day,

Monthly - This Month, Specific Month, Date Selection, Start Date, End Date,

Yearly - Specific Year

<div class="modal fade" id="reportModal" tabindex="-1" role="dialog" aria-labelledby="reportModalLabel"
    aria-hidden="true">
    <div class="modal-dialog modal-lg" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <h5 class="modal-title" id="reportModalLabel">Report Preferences <small>- will generate a PDF Report</small></h5>
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
            </div>
            <div class="modal-body">
                <div class="row">
                    <div class="col-md-12">
                        <h5>Daily</h5>
                        <div class="form-row py-3">
                            <label class="col-md-2">Specific Day</label>
                            <div class="col-md-5">
                                <select class="form-control" name="specificday">
                                    @if(!empty($firstRecord))
                                        @foreach($day as $date)
                                            <option value="{{$date->format('l')}}">{{$date->format('l-F-Y')}}</option>
                                        @endforeach
                                    @endif
                                </select>
                            </div>
                            <div class="col-md-5">
                                <a href="#" class="btn btn-block btn-primary">Generate Report</a>
                            </div>
                        </div>
                        <hr>
                        <h5>Monthly</h5>
                        <div class="form-row pt-3">
                            <label class="col-md-2">This Month</label>
                            <div class="col-md-5">
                                <input type="text" class="form-control" name="thismonth" readonly value="{{now()->submonth()->translatedFormat('F')}}">
                            </div>
                            <div class="col-md-5">
                                <a href="#" class="btn btn-block btn-danger">Generate Report for {{now()->submonth()->translatedFormat('F')}}</a>
                            </div>
                        </div>
                        <div class="form-row pt-3">
                            <label class="col-md-2">Specific Month</label>
                            <div class="col-md-5">
                                <select class="form-control" name="specificmonth">
                                    @if(!empty($firstRecord))
                                        @foreach($month as $date)
                                            <option value="{{$date->format('F-Y')}}">{{$date->format('F-Y')}}</option>
                                        @endforeach
                                    @endif
                                </select>
                            </div>
                            <div class="col-md-5">
                                <a href="#" class="btn btn-block btn-danger">Generate Report</a>
                            </div>
                        </div>
                        <div class="form-row py-3">
                            <label class="col-md-2">Date Selection</label>
                            <div class="col-md-3">
                                <label>Start Date</label>
                                <input type="date" value="{{$firstRecord->format('Y-m-d')}}" name="startDate" class="form-control">
                            </div>
                            <div class="col-md-3">
                                <label>End Date</label>
                                <input type="date" value="{{$lastRecord->format('Y-m-d')}}" name="endDate" class="form-control">
                            </div>
                            <div class="col-md-4">
                                <label>&nbsp;</label>
                                <a href="#" class="btn btn-block btn-danger">Generate Report</a>
                            </div>
                        </div>
                        <hr>
                        <h5>Yearly</h5>
                        <div class="form-row py-3">
                            <label class="col-md-2">Specific Year</label>
                            <div class="col-md-5">
                                <select class="form-control" name="specificyear">
                                    @if(!empty($firstRecord))
                                        @foreach($year as $date)
                                            <option value="{{$date->format('Y')}}">{{$date->format('Y')}}</option>
                                        @endforeach
                                    @endif
                                </select>
                            </div>
                            <div class="col-md-5">
                                <a href="#" class="btn btn-block btn-warning text-dark">Generate Report</a>
                            </div>
                        </div>
                        <hr>
                        <div class="row">
                            <div class="col-md-12 text-center">
                                <label>*Process will take time to Generate</label>
                                <a href="#" class="btn btn-block btn-info">Generate Complete Database Records</a>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

My calculation code is as follows:

@php
    $firstRecord = $accessReports->pluck('created_at')->first();
    $lastRecord = $accessReports->pluck('created_at')->last();
    $day = \Carbon\CarbonPeriod::create($firstRecord, '1 day', $lastRecord);
    $month = \Carbon\CarbonPeriod::create($firstRecord, '1 month', $lastRecord);
    $year = \Carbon\CarbonPeriod::create($firstRecord, '1 year', $lastRecord);
@endphp

It worked fine until the new record was put into the database and the daily - specific day, month and year no longer give a drop down of the info. I am wanting to get the first and last records in the database and only allow the user to select records between those dates that are available.

How can I make this possible if the records are in the same day, month or year? I am using a @foreach() to populate the "specific" selection options.

Dec
05
5 months ago
Activity icon

Awarded Best Reply on ShouldQueue Vs Job

Figured out the difference.

Activity icon

Replied to ShouldQueue Vs Job

Figured out the difference.

Activity icon

Replied to ShouldQueue Vs Job

If one is using a Command to send the mails, how does the above work in terms of a QueueJob or the ShouldQueue with QUEUE_CONNECTION=sync or QUEUE_CONNECTION=database

Activity icon

Started a new Conversation ShouldQueue Vs Job

Do you have to create a Queue Job if you using ShouldQueue in a Mailable?

I have been looking up how to que emails and was wondering if it is necessary to created a QueueJob if one is using ShouldQueue and QUEUE_CONNECTION=sync.

Is there a difference? Or do the mails just que up and send when possible? Whereas a QueueJob one can set the time delay and use QUEUE_CONNECTION=database.

Does the ShouldQueue make the site take time to send the email like when using the standard Maill::to()->send() or does it get stored and then sent when the Que Worker is running?

Slightly confused.

Nov
27
5 months ago
Activity icon

Replied to Multiple Arrays To Iterate Over

Wow this works excellently! It is only returning one array though, when checking via dd(); Also now I have learnt how to add global functions properly, thank you.

Illuminate\Support\Collection {#1268 ▼
  #items: array:1 [▼
    0 => array:4 [▼
      0 => "sdfasdfsadasdf"
      1 => "normal"
      2 => "2020-11-02"
      3 => "14"
    ]
  ]
}
Activity icon

Started a new Conversation Multiple Arrays To Iterate Over

Hi all, I hope that everyone is keeping safe. I have a form that makes several inputs in one line: description, priority, deadline, budget.

Each of these are returning as a separate array as expected, though I as wondering how I could insert the one row into it's own Array Example: [0] = description, priority, deadline, budget [1] = description, priority, deadline, budget

instead of having it:

request: Symfony\Component\HttpFoundation\ParameterBag {#44 ▼
    #parameters: array:6 [▼
      "_token" => "bHXw0BgEDZ5ugXotRk89SJU0eMjnuIsuWWCYL5bP"
      "project_id" => "5"
      "description" => array:1 [▶]
      "priority" => array:1 [▶]
      "deadline" => array:1 [▶]
      "sub_budget" => array:1 [▶]
    ]