richard

Member Since 4 Years Ago

Nairobi

Software Developer at Nairobi, Kenya

Experience Points 92,370
Experience Level 19

2,630 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 652
Lessons
Completed
Best Reply Awards 32
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.

09 Sep
1 week ago

richard commented on At A Glance

I love this 💯

04 Sep
2 weeks ago

richard left a reply on Date In Carbon

Your question is not clear... but I presume you want something like...

Model::whereMonth('created_at', '>=', now()->format('m'))
  ->whereYear('created_at', '>=', now()->format('Y'))
  ->whereDate('created_at', '<=', now()->addYears(4))
  ->get();

richard left a reply on How To Install Illuminate/html Package By Composer In Laravel 6

Hi @kaushal This package is abandoned and no longer maintained. The author suggests using the laravelcollective/html package instead.

02 Apr
5 months ago

richard left a reply on Authentication Problem

Simply implement MustVerifyEmail interface to force a user to verify their email first before logging in like this:

class User extends Authenticatable implements MustVerifyEmail

The purpose for Auth::routes(['verify' => false]) is to disable the email verification routes if you do not have any plan using them in your project.

01 Apr
5 months ago

richard left a reply on Authentication Problem

Let's solve 1 issue at a time. Your issue is that you want to be redirected to login page after registering. Did my solution fix your problem?

You can create a new thread for the second issue

richard left a reply on Authentication Problem

By default, the user is logged when he registers (Illuminate\Foundation\Auth\RegistersUsers.php). You need to override that logic by coping this method into app\Http\Controllers\Auth\RegisterController.php and deleting the login logic.

Remember to fix the Registered event path.

public function register(Request $request)
    {
        $this->validator($request->all())->validate();

        event(new Registered($user = $this->create($request->all())));

        $this->guard()->login($user); // delete this line

        return $this->registered($request, $user)
                        ?: redirect($this->redirectPath());
    }

richard left a reply on Count Every Fourth Record

@pickab00 You can count the number of reservations made in the database for that particular user. (Well, for guests, you cannot tell because there is no records saved)

richard left a reply on Axios: Provisional Headers Are Shown

I have experienced this before and here is the thing: Your browser is blocking the request because of the word "advert". Your ad blocker is configured to block such words that most people use in these annoying advertisements.

Just use any other word.

richard left a reply on Yajra Datatable With Relationship

The orders table will be like:

{data: 'id', name: 'id'},
{data: 'name', name: 'name'},
{data: 'price', name: 'price'},
{data: 'customer', name: 'customer.name'},
{data: 'employee', name: 'employee.name'},
{data: 'created_at', name: 'created_at'},
{data: 'updated_at', name: 'updated_at'}
27 Mar
5 months ago

richard left a reply on Where To Edit Spark Source Files?

From Sparks Terms of Service user the Software Modification section

You may alter, modify, or extend the Software for your own use, or commission a third-party to perform modifications for you, but you may not resell, redistribute or transfer the modified or derivative version without prior written consent from Laravel LLC.

You can copy the entire files and make modifications to suit your use case.

richard left a reply on How To Add Admin User In My Application

@tokoiwesley Ah, fellow Nairobian. Mambo kijana

@belhedi Go with Wesley's suggestion to avoid complexity in writing different auth drivers.

create three separate models (Admin, Teacher, Student) with each having a relationship to the User model for easily handling authentication.

richard left a reply on Access Token Validate From Another Server?

When you make an API call with the valid token, then you can receive the user info associated with that token. Then you can save them in the local storage or do anything you want with them.

richard left a reply on Laravel Must Provide A Mean To Disable View Caching

You can disable Caching from your browser like this.

Screenshot 2019-03-27 at 16 02 13

richard left a reply on Redirecting URL Problem

What backend framework are you using?

richard left a reply on How To Add Admin User In My Application

App\Teacher => uses teachers table
App\Student => uses students table

App\User => users table (for Admins only)

On login page, give them a dropdown to choose what kind of user they are. (Login as Student, Teacher or Admin)

Then inside your LoginController, check the option selected and login using a custom guard for that particular user.

richard left a reply on How To Add Admin User In My Application

@belhedi Checkout this article. It will give you a hint.

Different users have different roles. So you have to declare what permissions the admin, student, and the teacher has, because I believe they have separate access levels.

richard left a reply on How To Add Admin User In My Application

If only teachers will be logging in, you can use the teachers model for authentication. If students also log in, you need separate multiple authentication guards... but you have to declare their roles separately.

You can use Spatie's Permission library for managing roles.

25 Mar
5 months ago

richard left a reply on Logging

daily.

I can easily track the error logs per day and and see what the users experienced for that day

22 Mar
5 months ago

richard left a reply on How To Validate Two User Record In One Table

You can do this


    public function store(Request $request)
    {
        $data = $this->validate($request, [
            'product_name.*' => [
                'required',
                Rule::unique('products', 'product_name'))->where(function ($query) {
                    return $query->whereUserId(auth()->id);
                }),
            ],
            'other_attributes' => 'required|other_rules'
        ]);

        ...
}

richard left a reply on Why Do I Need To Use Extends Contoller?

The base controller comes with traits such as AuthorizesRequests, DispatchesJobs, ValidatesRequests which brings in more functionality into your controllers. For example, ValidatesRequests allows you to validate requests like this:


 public function store(Request $request)
 {
        $data = $this->validate($request, [
            'title' => 'required|min:3|unique:categories',
        ]);

    ...
}

But it is entirely optional to extend the Controller class.

richard left a reply on Ajax Incomplete Request Making

Show us the code making the Ajax call

20 Mar
5 months ago

richard left a reply on Helper Function Not Working Within My Package

Yeah, as @tykus has mentioned, you need to provide the full path. "src/Helpers/helper.php". Remember to run the composer dumpautoload thereafter.

richard left a reply on Can I Use Model Function Or Relationship Inside Eloquent?

You can do this in one simple method without the total_cost() method.


$orders = Order::all()->filter(function($order){
    return $order->ceremonies->sum('budget') > request('input');
});

richard left a reply on Helper Function Not Working Within My Package

Hmm. Is the path correct? Confirm it is not in app/Helpers/helper.php

richard left a reply on Helper Function Not Working Within My Package

You need to runcomposer dump-autoload to load it.

richard left a reply on Nova Custom Path

That is weird. Do you have /admin path on your routes/web.php file?

richard left a reply on Yajra Get Name Field From Another Table Using Foreign Key Stored In Main Table

You need to eager-load the manufacturers alongside car models

ublic function datatables()
    {
        $datatables = datatables(CarModels::with('manufacturer')->query()) // Set a CarModel belongs to manufacturer relationship
            ->editColumn('actions', function ($car_models) {
                return view('admin.car_models.datatables.actions', compact('car_models'));
            })
            ->rawColumns(['actions']);

        return $datatables->toJson();
    }

and then access it in your JavaScript as manufactuer.name

richard left a reply on Laravel Training

hi my name is Richard and I just rebooted my computer successfully.

richard left a reply on Trying To Get Property Of A Non-object In A Middleware

You need to check the user_type only when their is a logged in user like this:

public function handle($request, Closure $next)
    {
        if($request->user() && $request->user()->user_type == 'customer'){
            return $next($request);
        }

        return redirect('/')->with('error', 'You have not customer access');
    }

richard left a reply on Uncaught Error: Syntax Error, Unrecognized Expression:

What do you get with

stop: function () 
            {
              $('.sortable_lessons > li').each(function (i) {
        console.log(module_id)
                // $(this).find('#module_counter_' + module_id).html(i + 1);
              });
            }

richard left a reply on Empty Variable Check In Blade File

What are you trying to achieve in those if statements? Do you mean there are students who do not have names? :)

First of all, you need to do @foreach($students as $student) and not the other way round.

19 Mar
5 months ago

richard left a reply on I Want Query Laravel Model Please

I want query laravel Model please

Sure, go ahead and query it. No worries :)

18 Mar
6 months ago

richard left a reply on Route Group Prefix No Working

Show us the entire routes/web.php and App\Providers\RouteServiceProvider file.

richard left a reply on Chat System - Laravel , Redis And Socket.io

Forget about socket.io and other 3rd party services. Check this awesome solution by Beyond Code and Spatie https://docs.beyondco.de/laravel-websockets/

richard left a reply on Route Group Prefix No Working

There is no way accessing let's say yourapp.test/admin/dashboard will output such an error. Maybe you have hit the wrong route while testing.

richard left a reply on SQLSTATE[23000]: Integrity Constraint Violation

On your database config file, under MySQL change strict to false.

'strict' => false,

15 Mar
6 months ago

richard left a reply on Accessing Token Based API Route Via Vue/Axios

I'd save the token to the local storage when the user logins and loads the page for the first time. Thereafter I will retrieve the token and pass it to axios on the subsequent API request.

richard left a reply on Check If Polymorphic Relation Exists Returns Empty

When you delete a company or a scooter, simply delete the associated notification. I think that solves the problem.

So basically are available notifications have existing companies/scooter

richard left a reply on How To Sum Values Of Duplicate ID's

This is how I'd do. I don't know your use case, but this will give you a hint @m4martie

class ActivityPoint extends Model
{
    
}

class User extends Model
{
    public function points()
    {
        return $this->hasMany(ActivityPoint)
    }

    public function totalPoints()
    {
        return $this->points->sum('points');
    }
}
// Collection of users
$users = User::all();

foreach($users as $user)
{
    echo $user->name . " has " . $user->totalPoints() . " points."
}

// Single User
$user = User::findOrFail(1);
echo $user->name . " has " . $user->totalPoints() . " points."

richard left a reply on How To Sum Values Of Duplicate ID's

Do you want points for a collection of users or just 1 user?


$user = App\User::findOrFail(id_of_that_particular_user);

$points = ActivityPoint::where('points', $reports->points)->where('user_id', $user->id)->sum('points');
13 Mar
6 months ago

richard left a reply on Forge's Db.sh.swp File

I already deleted it. Thanks

10 Mar
6 months ago

richard started a new conversation Forge's Db.sh.swp File

There is this file .db.sh.swp which is taking crazy space on my /home/forge folder?

What is its purpose and can I delete it?

forge

23 Feb
6 months ago

richard started a new conversation Attaching A Resource With BelongsToMany

I have 2 models in my project (JobAdvert and Category) with a BelongsToMany relationship. I have added an Actionable trait to both models to record the actions. When I attach a model on the other resource it doesn't record any action. It records only when you detach the resource.

For example, I have attached 4 categories and detached 1. Only detach is recorded in the actions.

Is this an expected behavior or a bug?

nova

07 Feb
7 months ago

richard started a new conversation Display Timestamps For PODCASTS

Thanks for the great Work, Jeff.

I think it'd be great to display the time the podcasts were added/uploaded.

They look just odd without the timestamps.

04 Jan
8 months ago

richard left a reply on Return Items Separated Out By Date

Try this

@foreach ($latest as $date => $product)

//output the product details

@endforeach