ExpDev07

ExpDev07

Member Since 3 Months Ago

Experience Points
1,070
Total
Experience

3,930 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
1
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 1
1,070 XP
09 Aug
1 month ago

ExpDev07 left a reply on Slow Response Time? 600-700ms?

Awesome! But how do I setup the Laravel server on Apache? Is there some build command I have to run?

ExpDev07 left a reply on Help

500 means something internal happened. In your function getCarInfo(Request $request), before you return, try to do die($carNumberInfo).

Route::get('api/car/info/get/{car}', '[email protected]');
public function getCarInfo($number)
{
    $content = file_get_contents("https://rogg.is/bizServices/CarRegistry/XmlService/CarService/v0703/CarDataByNumber.aspx?user=user&password=pass&number=" . $number);

    preg_match('permno', $content, $carNumber);

    $carNumberInfo = $carNumber[0];

    die($carNumberInfo); // here 

    return $carNumberInfo;
}

Now try and access in your browser: /api/car/info/get/5and see what you get.

ExpDev07 left a reply on Help

Well, just give each of the inputs an id, and in your #getCarInfo(), when you get the response, just set the value of those inputs to whatever the response gives?

Using GET makes more sense also since you're fetching something, not posting-- but it shouldn't have anything to do with your 500 error. But then you should also change your URL to /api/car/info/get/{carNumber}.

ExpDev07 left a reply on The Server Responded With A Status Of 401 ()

If you have removed the auth middleware, then you really shouldn't receive a missing token (as you shouldn't need one).

ExpDev07 left a reply on The Server Responded With A Status Of 401 ()

Well, you could do that, but it's a hacky solution imo. All your API endpoints should be in your api.php.

ExpDev07 left a reply on The Server Responded With A Status Of 401 ()

Could you please take a look in /storage/logs/laravel.log and send the last logs?

ExpDev07 left a reply on The Server Responded With A Status Of 401 ()

Show your whole ApiController file.

ExpDev07 left a reply on The Server Responded With A Status Of 401 ()

Are you logged in??? Try inspecting element with your browser, see if you've got a "csrf_token" token in your "html" tag or "body". If you don't, then you're not logged in and it won't work. As I said, if you don't wanna be logged in, just remove the auth middleware:

Route::get('services/get', '[email protected]');
Route::post('car/info/get', '[email protected]');
Route::post('booking/create', '[email protected]');

Boom, you no longer have to be logged in to access those routes.

ExpDev07 left a reply on Slow Response Time? 600-700ms?

Well, when you do search, it's obv going to be slower. But just accessing https://google.com doesn't take 1.57 secs for you.

I have a Single Page Application, so I am relying on fast response times. I've got good internet, 600-700ms is unacceptable.

I will try to put it on a Apache server. How could I go about that tough? Just copy paste my whole application?

ExpDev07 left a reply on The Server Responded With A Status Of 401 ()

EDIT: I just noticed you do not have any signed in users. Well, you gotta be signed in to use any endpoint which uses the auth middleware, that's kind of the point of it. If you want to access those routes without being signed in/authenticated, just remove that middleware.

Just remove the

middleware('auth:api')->

Well, if you look in config/auth.php, and scroll down to guards, you'll see that web and api have two different drivers. The web uses session, which takes your CSRF token, while api uses token, which is that api-token I was talking about.

You can use session for api as well, but it'll require you to do some stuff. First, add the middlewares that it requires to your api middleware group.

In your App/Http/Kernel.php add:

/**
 * The application's route middleware groups.
 *
 * @var array
 */
protected $middlewareGroups = [
    'web' => [
        \App\Http\Middleware\EncryptCookies::class,
        \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,
        \Illuminate\Session\Middleware\StartSession::class,
        // \Illuminate\Session\Middleware\AuthenticateSession::class,
        \Illuminate\View\Middleware\ShareErrorsFromSession::class,
        \App\Http\Middleware\VerifyCsrfToken::class,
        \Illuminate\Routing\Middleware\SubstituteBindings::class,
    ],

    'api' => [
        'throttle:60,1',
        'bindings',
        \Illuminate\Session\Middleware\StartSession::class,
        \App\Http\Middleware\EncryptCookies::class,
        \App\Http\Middleware\VerifyCsrfToken::class,
    ],
];

You can now, in your config/auth.php, change token to session:

'guards' => [
    'web' => [
        'driver' => 'session',
        'provider' => 'users',
    ],

    'api' => [
        'driver' => 'session',
        'provider' => 'users',
        'hash' => false,
    ],
],

Now, in your requests, include your CSRF-token:

axios.defaults.headers.common = {
  'X-Requested-With': 'XMLHttpRequest',
  'X-CSRF-TOKEN': window.csrf_token
};

ExpDev07 left a reply on The Server Responded With A Status Of 401 ()

Can we see your axios request? You are using the auth:api middleware, which means you'll have to either:

  1. Add an api_token to all your queries as such: /api/services/get?api-token=thetoken.
  2. Add an Authorization header with Bearer prefixed: Authorization: Bearer thetoken.
  3. I believe you can also include it in the form body.

The token has to be associated with an user such as:

- id: 0
- name: A name
- api_token: thetoken

ExpDev07 started a new conversation Slow Response Time? 600-700ms?

Hey, when I serve my laravel application (php artisan serve) locally (even on a fresh install), Postman uses like 600-700ms to just access a simple route like

Route::get('test', function () {
    return response()->json([ 'test' => 'testing' ]);
});

This can't be acceptable? A simple response like that should max take 20-30ms. Caching config, routes, doing composer optimizations, etc will only help with like 20-30ms. Is this because of my machine or is it really THAT slow?

It shouldn't be an issue with Postman, as for example GET-ing https://www.google.com/ takes max 200ms with it being mostly down to 50ms.

Thanks.

What more stuff can I do? How would i go about putting the files on an actual apache server, and will it be quicker? (like much, down to 20-50ms?).

06 Jul
2 months ago

ExpDev07 left a reply on Ideas Of To Create A Simple Chats

You probably want to use Laravel's Broadcasting to ensure that you can update the chat without needing a page refresh.

ExpDev07 left a reply on All Of My Vue Componenets No Longer Rendering.

But do you also wrap that around your html in for example in your layout template?

<head>
    <!-- head stuff -->
</head>

<body>
    <!-- Your Vue components must find themselves inside here as defined in "el" when instantiating a new Vue -->
    <div id="app">
        <nav></nav>
        <div class="content">
            @yield('content')
        </div>
    </div>
</body>

In other blade templates, you can extend this layout and put all your Vue components inside

@section('content')
    <a-vue-component />
@endsection

Hope this helped!

03 Jul
2 months ago

ExpDev07 left a reply on Eloquent HasMany WhereIn

@BOBBYBOUWMANN - Youre right... I just cant get my head around how to apply it my case despite the examples that you so kindly provided.

02 Jul
2 months ago

ExpDev07 left a reply on Eloquent HasMany WhereIn

@BOBBYBOUWMANN - I sorted it like this. In my user model, I have the following function:

/**
 * Gets the bans if player is banned, otherwise null. In practise, one player will have more than
 * one identifier banned.
 *
 * @return mixed
 */
public function bans()
{
    // Due to how banning works, there might exist a ban record for each of the player's identifier (steam, ip address
    // rockstar license, etc), and it's important to get all.
    return Ban::whereIn('identifier', $this->identifiers);
}

And whenever I will ban a user, I just do it like this:

// Make an id which will represent this batch of bans.
$ban_id = self::makeBanId();

// Go through the player's identifiers and create a ban record for each of them.
foreach ($player->identifiers as $identifier) {
    // Make sure there's only one ban per identifier by updating if one already
    // exists.
    Ban::updateOrCreate(['identifier' => $identifier], [
        'identifier' => $identifier,
        'ban-id' => $ban_id,
        'banner-id' => Auth::user()->player->staff,
        'reason' => $request->get('reason')
    ]);
}

Is this a bad way of doing it or? Should I instead use has?

ExpDev07 left a reply on Eloquent HasMany WhereIn

@BOBBYBOUWMANN - Well, the bansWithIdentifiers relationship ship wont work.

What I want is if theres for example a ban record with the columns:

Ban:

  • id: 5
  • identifier: ip:123456789

and another one with the columns:

  • id: 10
  • identifier: steam:steam64

And a user with the columns:

User:

  • id: 100
  • identifiers: [steam:steam64, ip:123456789]

Then the bans function in user should return a HasMany relationship which contains both of those bans as they both have an identifier which matches the users identifiers. This is what I want.

ExpDev07 left a reply on Eloquent HasMany WhereIn

@BOBBYBOUWMANN - That would work, but this wouldnt really be two relationships though, right?

It would be one relationship for creating, and the other method would just be a getter? Right?

ExpDev07 left a reply on Eloquent HasMany WhereIn

@BOBBYBOUWMANN - Yes, youre right. But for convenience, I want to be able to for example call

$user->bans

and that will retrieve all the bans which has an identifier column that matches an identifier in the array. Then if I want to create one, I can do

$user->bans()->create(...).

01 Jul
2 months ago

ExpDev07 started a new conversation Eloquent HasMany WhereIn

Hey! I have a user model with an array of identifiers. An identifier can be either an IP address or something else. However, users can be banned. And this is done through their identifiers.

Therefore, I created a HasMany relationship like this thinking it would work:

public function bans()
{
    // Due to how banning works, there might exist a ban record for each of the player's identifier (steam, ip address
    // rockstar license, etc), and it's important to get all.
    return $this->hasMany(Ban::class)->whereIn('identifier', $this->identifiers);
}

And that did not work. I know why: because it will still look for the foreign key relationship, then apply the "whereIn" constraints. This is not what I want.

I want that, as long as there's a Ban model (entry) where the identifier matches one of the identifiers in the user's identifiers-array, then it should be added to that hasMany relationship. Any tips on how to achieve this?

And it is kind of important that it is done through relationships, as I want do do this later:

// Go through the users's identifiers and create a ban record for each of them.
foreach ($user->identifiers as $identifier) {
    $user->bans()->updateOrCreate(['identifier' => $identifier], [
        'issuer_id' => Auth::user()->id,
        'reason' => 'a reason'
    ]);
}

Thanks in advance!

20 Jun
3 months ago

ExpDev07 left a reply on SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column 'issuer' In 'field List'

@AURAWINDSURFING - Any way I could do it without using the factory method and just use the player model directly for relationship?

ExpDev07 left a reply on SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column 'issuer' In 'field List'

@AURAWINDSURFING - Yes, they definitely are. It's unclean that I have to manually set the id. Is there no way in Eloquent to use the actual model object to set as reference when creating a model?

ExpDev07 left a reply on SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column 'issuer' In 'field List'

@STAUDENMEIR - I did do that here, and it worked:

/**
 * Store a newly created resource in storage.
 *
 * @param Request $request
 * @param Player $player
 * @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
 */
public function store(Request $request, Player $player)
{
    // Create the warning and persist it to the database.
    $warning = $player->warnings()->create([
        'issuer' => Auth::user()->player,
        'message' => $request->get('message')
    ]);

    // Redirect user to their created warning.
    return view('warnings.show', [ 'warning' => $warning ]);
}

ExpDev07 left a reply on SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column 'issuer' In 'field List'

@AURAWINDSURFING - So I can't reference the player directly when creating a model such as:

// Get the player model by id
$id = 10;
$player = Player::get($id);

// Create a warning for this player and set the issuer to themselves
$warning = $player->warnings()-create(
    [ 'issuer' => $player, 'message' => 'a test message.' ]
);

// (in this example, should equal each other)
$warning->player; // player that recieved warning
$warning->issuer; // player that issued warning

ExpDev07 started a new conversation SQLSTATE[42S22]: Column Not Found: 1054 Unknown Column 'issuer' In 'field List'

Hey, I am trying to create a model through seeding but is getting the following error:

Illuminate\Database\QueryException  : SQLSTATE[42S22]: Column not found: 1054 Unknown column 'issuer' in 'field list' (SQL: insert into `warnings` (`message`, `issuer`, `player_id`, `updated_at`, `created_at`) values (Accusamus voluptas iure nobis eius ut. Recusandae possimus et ea dignissimos consequatur velit. Vel aliquam veritatis exercitationem quisquam aut. Fugit blanditiis dolores vel ut dolorem commodi est., {"id":1,"identifier":"steam:nonqui3491267","name":"Sabrina Sauer","identifiers":"[\"steam:nonqui3491267\", \"162.23.60.34\"]","playtime":1306,"seen":"2019-06-20 20:03:14","cid1":null,"cid2":null,"cid3":null,"cid4":null}, 1, 2019-06-20 20:03:14, 2019-06-20 20:03:14))

My seeder looks as following:

/**
 * Run the database seeds.
 *
 * @return void
 */
public function run()
{
    // Faker to create data.
    $faker = Factory::create();

    // And now, let's create a few users in our database:
    for ($i = 0; $i < 50; $i++) {
        // Create a user with some properties.
        $user = User::create([
            'identifier' => 'steam:' . $faker->word . $faker->word . $faker->numberBetween(0, 10000000),
            'username' => $faker->name,
            'avatar' => self::$AVATAR_URL
        ]);

        // An IP address.
        $ipAddress = $faker->ipv4;

        // Create a player for this user.
        $player = $user->player()->create([
            'name' => $user->username,
            'identifiers' => json_encode([ $user->identifier, $ipAddress ]),
            'playtime' => $faker->numberBetween(0, 10000),
            'seen' => Carbon::now()
        ]);

        // Give the player some warnings and self as issuer.
        $player->warnings()->create(
            [ 'message' => $faker->text, 'issuer' => $player ]
        );
    }
}

As you can see, I'm trying to create a new warning for the player, and just set the issuer as themselves. The player model has the following relationship:

/**
 * Gets the warnings that this person has received.
 *
 * @return \Illuminate\Database\Eloquent\Relations\HasMany
 */
public function warnings()
{
    return $this->hasMany(Warning::class);
}

And the Warning model has the following relationships:

/**
 * Gets the player that received this warning.
 *
 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
 */
public function player()
{
    return $this->belongsTo(Player::class);
}

/**
 * Gets the player that issued this warning.
 *
 * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
 */
public function issuer()
{
    return $this->belongsTo(Player::class);
}

As you can clearly see, there is an "issuer" which I am trying to set in the seeder. In the seeder, "player" and "issuer" should be the same Player. In the migration, I do have an unsigned big integer for the "issuer_id".

Any help would be greatly appreciated, thanks!