ctyler

ctyler

Member Since 1 Year Ago

Experience Points
16,820
Total
Experience

3,180 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
158
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.

Level 4
16,820 XP
Feb
14
1 week ago
Activity icon

Replied to How To Sort In A Foraech Statement

@talinon Perfect! That's exactly what I was looking for!

Activity icon

Started a new Conversation How To Sort In A Foraech Statement

Good morning all, I have something that I want to do but I am having an issue thinking through this and was hoping someone can help me.

So I am working on my permissions page and I have quite few for each role:

assignment_add
assignment_delete
assignment_update
assignment_view
attendance_add
attendance_delete
attendance_ipdate
attendance_view
attendanceSession_add
attendanceSession_delete
attendanceSession_update
attendanceSession_view
certificate_add
certificate_delete
certificate_update
certificate_view
course_add
course_close
course_delete
course_open
course_update
course_view
courseCategory_add
courseCategory_delete 

Just to name a few. On the page they are in 4 rows not in a single list. Anyway, I would like to break these up a little based on the string before the "_". So once the assignment_ is done I would like to insert a break or maybe even create a header before each one. Just to add some separation. Any ideas?

Feb
13
1 week ago
Activity icon

Replied to Attach And Detaching To Quickly Results In A Constraint Violation

@bobbybouwmann ,

Sorry it took me so long to get back to you.

I ended up enclosing the Enrollment method in a try catch block.

try {
            Enrollment::enrollUser($enrollment, $user, $enrollmentId);
        } catch (\Illuminate\Database\QueryException $e) {
            if($e->errorInfo[0] == '23000') {
                $message[] = 'You are already enrolled in this course.';
                return $message;
            } else {
                $message[] = 'There has been an error! Please try again.';
                return $message;
            }
        }

This has fixed this issue. There is no error being reported no matter how fast you click the enroll and un-enroll.

You wouldn't happen to know why this was an issue in only explorer by any chance would you?

Feb
09
1 week ago
Activity icon

Started a new Conversation Attach And Detaching To Quickly Results In A Constraint Violation

Hello All, I am having an interesting issue in Internet Explorer 11. I have an application where student can enroll and un-enroll themselves in class. This is done via attach and detach statement:

Enrolling

$enrollment->users()->attach($user->id, ['enroll_code' => $enrollmentId]);

Un-enrolling $user->enrollments()->detach($enrollment->id);

If the user is enrolled an un-enroll button is shown

If the user is not enrolled an enroll now button is shown.

I have a unique index set up on user_id and the course_id on the enrollment table.

Now, in Chrome, Firefox, and Edge I can click this button as fast as I can without issue. However, in IE 11, if I do that I get a constraint violation:

SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry '91-6' for key 'PRIMARY' (SQL: insert into `enrollment_user` (`created_at`, `enroll_code`, `enrollment_id`, `updated_at`, `user_id`) values (2020-02-09 10:40:07, 916Q1FGO, 91, 2020-02-09 10:40:07, 6))

I tried adding javascript to the page to make sure the buttons (both enroll and un-enroll) are disabled until the page loads via:

setting the buttons to disabled and then adding:

$(document).ready(function(){
            $('.prevent-dbl-submit').attr('disabled',false);
        });

I still get the error.

In the Controller is there anyway to make sure the query has completed before calling:

return back();

or is there another way to handle this?

Dec
11
2 months ago
Activity icon

Replied to Difficulty Translating A Query To Query Builder

Good Afternoon all. I did come up with a work around with a DB::select.


$data = DB::select(
                'select *
                        from users
                        join provider_user on users.id = provider_user.user_id
                        WHERE provider_user.provider_id = :provider
                        AND (firstname LIKE :query1
                        OR lastname LIKE :query2
                        OR lastname LIKE :query3)', ['provider'=> $provider_user->provider_id, 'query1' => '%'.$query.'%', 'query2' => '%'.$query.'%', 'query3' => '%'.$query.'%']
            );


Why am I using query1, query2 etc when they are all the same. You cannot reuse a name parameter. However, my initial post still stands. Wh would that not work?

Activity icon

Started a new Conversation Difficulty Translating A Query To Query Builder

I am working on an ajax query shown here:

SELECT * 
FROM users
join provider_user on users.id = provider_user.user_id
WHERE provider_user.provider_id = 16 (this will be a parameter)
AND (firstname LIKE '%r%'
or lastname LIKE '%r%'
or email LIKE '%r%')

This returns 3 results which is correct - no duplicates. However, when I convert it to Laravel Query Builder it is returning a user 3 times for a total of 5 times. Here is the code for the query builder:

$provider_user = Auth::user(); (This is 16)
$query = $request->get('query');
            $data = DB::table('users')
                ->join('provider_user', 'users.id', '=', 'provider_user.user_id')
                ->when($query, function($localquery, $query) {
                    return $localquery->where('firstname', 'LIKE', '%'.$query.'%')
                        ->orWhere('lastname', 'LIKE', '%'.$query.'%')
                        ->orWhere('email', 'LIKE', '%'.$query.'%');
                })
                ->where('provider_user.provider_id', '=', $provider_user->provider_id)
                ->get();

Any help would be appreciated.

Nov
15
3 months ago
Activity icon

Replied to Laravel Trying To Write Log Files To Local Project Location Instead Of Remote

@alanholmes Thank you so much for the quick response. I have been trying to fix the issue on the remote. I ran dump autoload and clearing all the caches. None of it worked until I ran all of that locally. Now it is working correctly.

Activity icon

Started a new Conversation Laravel Trying To Write Log Files To Local Project Location Instead Of Remote

Good Morning, I started having an issue with my laravel project and I've been developing it for a while now. The trouble started when I tried removing telescope and then reinstalling. I was having issues after un-installing so I reloaded a copy.

I am developing local on my machine and uploading files automatically. My project is currently as E:\www\laravelproject

The remote files are located at /var/www/html/laravelproject. This is where the web server is.

So now when I try to load the page i get: file_put_contents(E:\www\laravelproject\storage\framework/sessions/ov9via7jcPQHSh5U5cTAN6OIfxIpDko9hPKp597R): failed to open stream: No such file or directory

This is odd because it is trying to find the local directory on the remote server. It should be trying to write to /var/www/html/laravelproject/storage/framework/sessions/ov9via7jcPQHSh5U5cTAN6OIfxIpDko9hPKp597R

Where does laravel get the directory from? Could this be from composer? I cannot seem to find the location to correct this. Any help in this matter would be appreciated.

Thank you Casey

Oct
25
3 months ago
Activity icon

Awarded Best Reply on Can You Use An Aggregate On A Nested Eager Load?

I just figured it out. This works perfectly.

$courses = Course::with('attendance.attendancesessions')
            ->when($cat, function ($query, $cat){
                return $query->where('course_cat_id', $cat);
            })
            ->when($from, function ($query, $from) {
                return $query->where('start_date', '>=', $from); //2020-02-01
            })
            ->when($to, function ($query, $to) {
                return $query->where('start_date', '<=', $to); //2020-02-29
            })
            ->sortable(['start_date' => 'desc'])
            ->paginate(25);

Then output in view:

@foreach($courses as $course)
            <tr>
                <td class="text-center">{{  $course->id }}</td>
                <td class="text-left"><a href="#">{{  $course->name }}</a> </td>
                <td class="text-center">{{ \Carbon\Carbon::parse($course->start_date)->format('m/d/Y') }}</td>
                <td class="text-center">
                    {{ (empty($course->attendance->attendancesessions->last()->session_date) ? $course->end_date : \Carbon\Carbon::parse($course->attendance->attendancesessions->last()->session_date)->format('m/d/Y')) }}

                </td>
    </tr>
@endforeach
Activity icon

Replied to Can You Use An Aggregate On A Nested Eager Load?

I just figured it out. This works perfectly.

$courses = Course::with('attendance.attendancesessions')
            ->when($cat, function ($query, $cat){
                return $query->where('course_cat_id', $cat);
            })
            ->when($from, function ($query, $from) {
                return $query->where('start_date', '>=', $from); //2020-02-01
            })
            ->when($to, function ($query, $to) {
                return $query->where('start_date', '<=', $to); //2020-02-29
            })
            ->sortable(['start_date' => 'desc'])
            ->paginate(25);

Then output in view:

@foreach($courses as $course)
            <tr>
                <td class="text-center">{{  $course->id }}</td>
                <td class="text-left"><a href="#">{{  $course->name }}</a> </td>
                <td class="text-center">{{ \Carbon\Carbon::parse($course->start_date)->format('m/d/Y') }}</td>
                <td class="text-center">
                    {{ (empty($course->attendance->attendancesessions->last()->session_date) ? $course->end_date : \Carbon\Carbon::parse($course->attendance->attendancesessions->last()->session_date)->format('m/d/Y')) }}

                </td>
    </tr>
@endforeach
Activity icon

Started a new Conversation Can You Use An Aggregate On A Nested Eager Load?

Hello all, So i have a database that contains courses. Each course has one attendance. Each attendance can have multiple Sessions. The course table has the start_date column. The end date for the course is the last session. I am currently using a sub query for this:

$end_date = DB::table('attendances')
            ->select('attendances.course_id', DB::raw('MAX(attendancesessions.session_date) as end_date'))
            ->leftjoin('attendancesessions', 'attendances.id', '=', 'attendancesessions.attendance_id')
            ->groupBy('attendances.course_id');

$courses = $course
            ->JoinSub($end_date, 'end_date', function ($join) {
                $join->on('id', '=', 'end_date.course_id');
            })
            ->when($cat, function ($query, $cat){
                return $query->where('course_cat_id', $cat);
            })
            ->when($from, function ($query, $from) {
                return $query->where('start_date', '>=', $from); //2020-02-01
            })
            ->when($to, function ($query, $to) {
                return $query->where('start_date', '<=', $to); //2020-02-29
            })
            ->sortable(['start_date' => 'desc'])
            ->paginate(25);

This works okay but I was wondering if I could use an Aggregate on a Nested Eager Load some how.

$cousres = Course::with('attendance.attendancesessions')
        ->get();
        foreach($cousres as $course) {
            dd($course->attendance->attendancesessions->last());
        }

This works but I need to use last() with a column session_date. When I try to pass session_date via:

$course->attendance->attendancesessions->last('session_date')

I get an error: Argument 1 passed to Illuminate\Support\Collection::last() must be callable or null, string given, called in /var/www/html/dev-cls-training-com/app/Http/Controllers/Admin/CourseController.php on line 71

Oct
07
4 months ago
Activity icon

Replied to Stored Procedure Always Return An Empty Array

OMG. Turns out I did not convert my Variables into the parameters when changing to stored procedure. How embarrassing. Sorry.

Activity icon

Started a new Conversation Stored Procedure Always Return An Empty Array

Good After noon all. I am having an issue running a stored procedure in a Controller: Laravel 5.8 Mariadb: 10.4.8

Here is the stored procedure:

DELIMITER $$
CREATE DEFINER=`dbuser`@`10.6.12.18` PROCEDURE `GetStudentsToGrade`(
    IN course_ID INT,
    IN assignmentID INT
)
BEGIN
    SELECT c.id as courseID, c.name, count(sess.id) as TotalSessions, y.userID, y.firstname, y.lastname, y.NoAttended, y.SessionID, y.updated_at, z.grade, z.updated_at
FROM courses c
JOIN attendances a on c.id = a.course_id
left join attendancesessions sess on a.id = sess.attendance_id
LEFT JOIN
(
                SELECT c.id as courseID, u.id as userID, u.firstname, u.lastname, sess.id as SessionID, count(al.status) as NoAttended, al.updated_at
                FROM attendancelogs as al
                join attendancesessions sess on al.attendancesession_id = sess.id
                join attendances a on sess.attendance_id = a.id
                join courses c on a.course_id = c.id
                join users u on al.user_id = u.id
                WHERE c.id = @courseID
                AND al.status = 1
    GROUP BY userID, courseID
) as y on c.id = y.courseID
LEFT JOIN
(
                SELECT users.id, users.firstname, users.lastname, assign_grades.grade, assign_grades.updated_at, assign_grades.assignment_id
                FROM assign_grades
                LEFT JOIN users on assign_grades.user_id = users.id
                JOIN assignments on assign_grades.assignment_id = assignments.id
                WHERE assignments.id = @assignmentID
) as z on y.userID = z.id
WHERE courseID = @courseID
GROUP BY y.userID, c.id
HAVING  TotalSessions = y.NoAttended;
END$$
DELIMITER ;

If I run this in MySQL Workbench I get the result I expect.

CALL GetStudentsToGrade(5, 97);

Now in the controller:

$studentsToGrade = DB::select(DB::raw("call GetStudentsToGrade('$course->id', '$assignment->id')"));

dd($studentsToGrade, $course->id, $assignment->id);

The dump show:

[]

5

97

I also tried:

$studentsToGrade = DB::select(DB::raw("call GetStudentsToGrade(5, 97)"));

With the same results. I cannot seem to figure out why this is not working,

Any help would be greatly appreciated.