tokoiwesley

tokoiwesley

Member Since 2 Years Ago

Nairobi

Experience Points
40,290
Total
Experience

4,710 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
310
Lessons
Completed
Best Reply Awards
13
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 9
40,290 XP
Sep
28
2 weeks ago
Activity icon

Replied to Arrow Function Inside A If Statement

As @tykus has pointed out, you need to declare your arrow function. Using your example...

did_we_find_item_to_remove ="no";
is_thier_pagination = "no";

let myArrowFunction = () => console.log("We are in");

if(did_we_find_item_to_remove != "yes" && is_thier_pagination != "yes")

{

    myArrowFunction();

} else {

    console.log("We are out");

}
Activity icon

Commented on Eloquent Subquery Additions

Thanks for the lesson.

Jul
16
3 months ago
Activity icon

Replied to Weird 'Function Name Must Be A String' With Auth:api

@matthewh Well, I have figured out that this error is due to improperly registering the said middleware in app/Http/Kernel.php. On correcting my mistake everything is fine and works as expected.

Activity icon

Replied to Laravel Passport: 'Function Name Must Be A String' Error

On trying to reproduce the error on a separate project, I figured out what the issue was;

I missed to properly register the CheckClientCredentials::class middleware in app/Http/Kernel.php. Everything is now working perfectly.

Activity icon

Replied to Vue.js Vs Angular:

@mahaveer Frameworks and languages are just tools. They have both strengths and weaknesses depending on the context (task/project) because of how they work (are designed to work) internally.

So without a specific project at hand (no variables to consider) it's just as @tykus stated!

Activity icon

Replied to Weird 'Function Name Must Be A String' With Auth:api

@tray2 I don't exactly see how I have hijacked the thread! I wanted to know whether a solution was found because the problem @matthewh experienced is identical to what am experiencing. Nevertheless, I have created a new thread for my issue.

Activity icon

Started a new conversation Laravel Passport: 'Function Name Must Be A String' Error

I have a working implementation of Laravel Passport that has only uses Password Grant tokens for authentication of users. So on trying to implement Client Credentials Grant for server-to-server authentication, the client middleware throws a weird error I have never encountered before: "Function name must be a string" whenever I apply it on any route I want to protect.

  • php: 7.1.3
  • laravel framework: 5.7.25
  • laravel passport: 7.0
"message": "Function name must be a string",
    "exception": "Symfony\Component\Debug\Exception\FatalThrowableError",
    "file": "/var/www/html/mochange/project.test/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php",
    "line": 152,
Activity icon

Replied to Weird 'Function Name Must Be A String' With Auth:api

@matthewh Did you find a solution?

I am getting this error as well when I tried to implement machine-to-machine (server-to-server) authentication (using client credentials) . In my case the auth:api middleware works perfectly fine, but the client middleware throws the same error described above.

Jun
11
4 months ago
Jun
07
4 months ago
Activity icon

Replied to Laravel Passport Test

You don't need to add any controllers. Before diving into Laravel passport testing, you need to be familiar with writing tests in Laravel.

Activity icon

Replied to Prevent Factory Duplication For Models Relationships

Yes, there is another way. Modify your Seeder as shown below:

use App\Thread;
use App\Tag;

factory(Thread::class, 60)->create();

Thread::all()->each(function ($thread){
factory(Tag::class, 10)->create(['thread_id'=> $thread->id]);
});
Activity icon

Replied to Tokenmismatchexception With Script

First, don't encrypt the csrf_token(). Pass it exactly the way it is generated. Next, I can see in your script you are setting the X-XSRF-TOKEN header. Have you tried using the X-CSRF-TOKEN header instead?

Jun
03
4 months ago
Activity icon

Replied to Relationship HasMany() Dosen't Work

@RESPECT - Then maybe you are using migrations the wrong way. They are meant exactly for this type of job in the first place - easily modifying tables in production.

May
28
4 months ago
Activity icon

Replied to Project Not Being Created

@swimmer using @nakov's solution should solve the issue. Your Laravel project folder will be Medici.

Activity icon

Replied to Project Not Being Created

What do you want the name of your project folder/directory to be?

Activity icon

Replied to Relationship HasMany() Dosen't Work

I created these tables in production manually without migration what i forget

@respect editing code directly in production is a terrible idea. I suggest you write the code in your local environment and test it before moving/deploying it to production.

May
22
4 months ago
Activity icon

Replied to Insert Multiple Data Into Database

@EMFINANGA - Say for example a customer can have many orders. Your orders table should have the relevant column to accommodate this relationship then you'll define the relationship and it's inverse in the respective models.

I have used the customers to represent your customer_details table;

customers - id - name ...

orders - id - customer_id ...

Customer model class

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Customer extends Model
{
    protected $guarded;

    public function orders()
    {
        return $this->hasMany(Order::class, 'customer_id', 'id');
    }
}

Order model class

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Order extends Model
{
    protected $guarded = [];

    public function customer()
    {
        return $this->belongsTo(Customer::class, 'customer_id', 'id');
    }
}

When a customer makes an order, you need to retrieve the relevant customer model (record) and create a related order model (record). Example;

<?php

namespace App\Http\Controllers;

use App\Order;
use App\Customer;
use Illuminate\Http\Request;

class OrdersController extends Controller
{
    public function store(Request $request)
    {
        $customer = Customer::find(1);

        Order::create([
            'customer_id' => $customer->id,
            ...
        ]);
    }
}
May
20
4 months ago
Activity icon

Replied to Insert Multiple Data Into Database

If I get your question, you need to use a relationship between the two tables.

May
15
5 months ago
Activity icon

Replied to Laravel Csrf Token Mismatch In POST Request With URL

@CRAZYLIFE - Then you will need to use the second solution I have suggested above (exclude /response from CSRF protection)

Activity icon

Replied to Laravel Csrf Token Mismatch In POST Request With URL

If you don't want to pass the token then exclude /response from CSRF protection in /app/Http/Middleware/VerifyCsrfToken.php file;

/**
* The URIs that should be excluded from CSRF verification.
*
* @var array
*/
protected $except = [
    'response',
];

or

protected $except = [
    'http://www.test.com/response',
];
Activity icon

Replied to Laravel Csrf Token Mismatch In POST Request With URL

Use the @csrf Blade directive to generate the token field

<form method="POST" action="/response">
    @csrf
    ...
</form>
May
07
5 months ago
Activity icon

Replied to How To Create Relationships?

@ALEX_STORM - You are welcome.

Activity icon

Replied to How To Create Relationships?

@ALEX_STORM - Each model is mapped to a table thus each component becomes an entity of its own.

Activity icon

Replied to How To Create Relationships?

Check out Eloquent Relationships to learn more about relationships in Laravel's Eloquent ORM.

This explanation about normalizing a database can help you understand the need to split a single table into multiple tables.

Activity icon

Replied to How To Create Relationships?

Your question is not very clear. Are you working alongside a tutorial?

May
05
5 months ago
Activity icon

Replied to .gitignore - Doesn't Work As Expected

There is a second step to "ignoring" the file since you had already committed it to the remote repo;

git rm --cached config/snappy.php

and then committing the change.

However, personally I'd be comfortable with @snapey's suggestion.

Activity icon

Replied to Consuming Your API With JavaScript

@BURYO - You are welcome. I had mentioned about a change that was made to Laravel in how it handles cookie serialization. You can find out more about this in the article Security Release: Laravel v5.6.30 and v5.5.42 have been released and the official upgrade guide Upgrading To 5.6.30 From 5.6 (Security Release)

Activity icon

Replied to Consuming Your API With JavaScript

@BURYO - Change this protected static $serialize = true; to

protected static $serialize = false;
Activity icon

Replied to Consuming Your API With JavaScript

@BURYO - That's OK. It's supposed to be in the request headers and not response headers.

Activity icon

Replied to Consuming Your API With JavaScript

Are you getting laravel_token in the response headers?

Activity icon

Replied to Consuming Your API With JavaScript

Try adding Passport::withoutCookieSerialization(); in the boot method of the AppServiceProvider (app/Providers/AppServiceProvider.php) to see whether that solves the problem.

Activity icon

Replied to Consuming Your API With JavaScript

This problem may be due to a change in how Laravel handles cookie serialization. Which version of Laravel are you using?

Apr
24
5 months ago
Activity icon

Replied to Access Token Validate From Another Server?

Well, if I would have to implement something like that - since this seems to me to be a machine-to-machine authentication issue - I would opt for the Client Credentials Grant Tokens in Laravel Passport. Let me know if this helps.

Apr
15
6 months ago
Activity icon

Replied to Laravel Passport Correct Usage

@MIKO55 - You are welcome.

Activity icon

Replied to Laravel Passport Correct Usage

@MIKO55 - Yes, it's the solution.

Activity icon

Replied to Laravel Passport Correct Usage

Passport::withoutCookieSerialization() instructs Passport to disable cookie serialization.

There was a Laravel release (5.6.30 and 5.5.42) early August 2018 that contained a breaking change to cookie encryption and serialization logic. It included an upgrade to Passport code that serializes cookies as well.

Activity icon

Replied to Laravel Passport Correct Usage

@MIKO55 - You are using Apache web server so it's possible that the Authorization Header is being blocked by a module in Apache. Some devs who have experienced this issue before recommend adding the following in your .htaccess file;

RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]

Also ensure that the .htaccess file located in the public folder of your app has the following lines;

RewriteCond %{HTTP:Authorization} ^(.+)$
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
Activity icon

Replied to Laravel Passport Correct Usage

Could it be an environment setup issue! Which web server and OS are you using?

Activity icon

Replied to Laravel Passport Correct Usage

Check whether you have included the CSRF token in your application layout file.

<meta name="csrf-token" content="{{ csrf_token() }}">
Activity icon

Replied to Laravel Passport Correct Usage

@MIKO55 - What response are you getting?

Activity icon

Replied to How To Always Run Multiple Queues At All Time Via Supervisor?

Maybe it's because you are dispatching all the jobs and/or queueable entities in your app to only one queue (the default queue). Is this the case?

Apr
14
6 months ago
Activity icon

Replied to Laravel Passport Correct Usage

As I tried to reproduce this issue, I found out was that the X-Requested-With header has already been added in ./resources/js/bootstrap.js. Adding it elsewhere in the code (say app.js) results in the Vue component always returning Unauthenticated. So try deleting the X-Requested-With header addition you made before and test again.

Activity icon

Replied to Laravel Passport Correct Usage

@MIKO55 - Well I was assuming you had already run php artisan make:auth! At least you now have the laravel_token cookie, so we can focus on why the Vue component is returning Unauthenticated.

I am not sure what exactly you mean by stateless requests and web requests.

APIs do not maintain session state between requests.

Apr
13
6 months ago
Activity icon

Replied to Laravel Passport Correct Usage

@MIKO55 - You seem to be mixing up stuff. After successful authentication in the Web app, you do not need to manually create a token (in your code) at all.

$success['token'] =  $user->createToken('MyApp')->accessToken;

That's the essence of adding \Laravel\Passport\Http\Middleware\CreateFreshApiToken::class in the web middleware group. Laravel creates the token for you automatically, such that all you need is to make requests to the API endpoints (routes) using axios (or any other way in JavaScript).

Just to mention, ensure that you are handling API requests as stateless requests and Web requests as session-based. It's a good practice to write the logic for the two cases in different controllers because of other concerns such as validation etc.

Activity icon

Replied to Laravel Passport Correct Usage

@MIKO55 - What tool are you using for your XMLHttpRequests?

Apr
10
6 months ago
Activity icon

Replied to Eloquent Methods And Collection Methods

@zaster I have added an edit to my initial reply.