Bvanhaastrecht

Bvanhaastrecht

Member Since 7 Months Ago

Experience Points
570
Total
Experience

4,430 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
0
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 1
570 XP
Oct
02
2 months ago
Activity icon

Replied to Trying To Get Property Of Non-object With Relation

Got into this again. The with function is the same name as the column, I think therefore when I try to access it, it gives me the primary column value and not the foreign.

When outputting to JSON it is uitputting the foreign data, while accessing as object it returns the column value.

How to get the foreign data with with?

Aug
13
4 months ago
Activity icon

Replied to Unable To Retrieve Request Body With POST Method

Got it, using trailing slash I get no body, with no trailing slash it works.

Works:

POST https://url/api

No body:

POST https://url/api/

Is this as expected?

Activity icon

Replied to Unable To Retrieve Request Body With POST Method

api.php

Route::post('/', '[email protected]');

BaseController.php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class BaseController extends Controller
{
    public function apiRoot(Request $request)
    {
       var_dump($request->getContent());
       exit;
    }
}

As you can see I'm trying to get POST from api root directory. Just tested with an nested directory, and this does contain POST body. So the issue is only when trying to get body from root of /api/.

Because of migration from a non-laravel to Laravel app I need to have POST with body in API root.

Activity icon

Replied to Unable To Retrieve Request Body With POST Method

Thanks, but the string of getContent() is empty, and so is all().

Activity icon

Started a new Conversation Unable To Retrieve Request Body With POST Method

Hello,

Just banging my head on something very simple. I'm doing POST request with application/json RAW body data in Postman. I'm unable to get this JSON body data in Laravel.

Using Laravel 5.8 I should be seeing data in $request->getContent(), but it's empty.

Disabled CSRF, disabled every Middleware without success.

Any ideas?

Thanks, Bastiaan

Activity icon

Replied to Search For Null In Collection Stange Result

I see, thank you very much for the help and explanation!

Activity icon

Replied to Search For Null In Collection Stange Result

Yes indeed, $invoices is a Collection.

The values() method indeed solves this. Thanks!

So getting a subset of a collection where the result doesn't contain the first row, keys are added to the rows. Is this how it works?

Activity icon

Started a new Conversation Search For Null In Collection Stange Result

Hello,

When I request rows where some column is null, the return format is different then from searching that same column for a value.

With value:

$invoices->where('contract_id', '00000185');

object(Illuminate\Database\Eloquent\Collection)#785 (1) {
["items":protected]=>
array(19) {
[0]=>
object(App\Models\CustomerInvoices)#817 (26) {

In JSON looks like (correctly):

[{
    "column1" : "data",
    "column2" : "data",
},
    "column1" : "data",
    "column2" : "data",
}]

Search for null:

$invoices->where('contract_id', null);

object(Illuminate\Database\Eloquent\Collection)#785 (1) {
["items":protected]=>
array(5) {
[19]=>
object(App\Models\CustomerInvoices)#836 (26) { ...

In JSON looks like (incorrect, different from with value search):

{
    "19": {
        "column1" : "data",
    "column2" : "data",
    },
    "20": {
        "column1" : "data",
    "column2" : "data",
    }
}

So you see with search for null each row gets a key. Because I'm outputing directory to json, I would like both outputs to look the same. Any idea why this happens?

Regards, Bastiaan

Jul
16
5 months ago
Activity icon

Replied to Mass Assign With Input Filter

Adding the columns to $filleable would work, but as described in my initial post, we have a lot of tables and large ones to. It would require a lot of work to fill the $fillable's, but it isn't smart so to speak.

I'm looking for a way we don't need to fill all the $fillable's. Using $guarded will work for input names we know and want to filter, but that doesn't work for unknown input names.

I'm seeking something like:

$guarded = ['send-email', 'any other not known table column'];
Activity icon

Replied to Mass Assign With Input Filter

This will not protect the model from filtering unwanted/unknown input's.

We use hidden inputs to give additional info into the request. But these should not be used in the mass assignment.

<input type="hidden" name="send-email" value="true">
<input type="text" name="name">
<input type="text" name="asset">

In this example, the 'send-email' should not be used in mass assignment. Secondly, for security reasons I would like to filter the request inputs to be only what is accepted by the model. These are unpredictable input names, so therefore dynamically filtering by column name would work, but how :-)

Activity icon

Started a new Conversation Mass Assign With Input Filter

Hello,

I would like to filter out input fields who not exist as a column in the table. I was thinking of something like:

$asset = new \App\Models\CmdbAssets();
$asset->create($request->only($asset->getFillable()));

I have my model setup as:

class CmdbAssets extends Model
{
    protected $table = 'cmdb_assets';
    protected $guarded = ['customer'];
}

I would expect the getFillable() would return my fillable attributes who are not guarded, so all of them. But the array is empty. I could fill the $fillable in the model, but we have a lot of large tables and wouldnt make sense. The $guarded way is much more clean.

Is there another way to accomplish input filtering in mass assignment?

Regards, Bastiaan

Jul
07
5 months ago
Activity icon

Replied to Trying To Get Property Of Non-object With Relation

Interesting,

echo $rag->customer;

Returns 146;

As in the id field, seems like the relation is not there.

Activity icon

Started a new Conversation Trying To Get Property Of Non-object With Relation

Hello,

I'm pulling my hair over here. I'm trying to access an relation, but it's telling me there isn't one. While when I convert it to json, it's defenetely there.

{
    protected $table = 'customer_rag';

    public function customer()
    {
        return $this->belongsTo('App\Models\Customers', 'id', 'customer');
    }
}
$rags = \App\Models\CustomerRag::with(['customer'])
  ->where('level', 1)
  ->orWhere('level', 2)
  ->get();

foreach ($rags as $rag) {
  echo $rag->customer->customer;   //should give the customer property, string name
}

Throws: Trying to get property of non-object

While: $rag->toJson();

Gives:

{
    "id":5,
    "customer":{
        "id":146,
        "customer":"Test customer name",
        "email":"[email protected]",
        "created":"2017-09-14",
        "deleted":0
    },
    "level":1,
    "reason":"Test reason",
    "changed":"2018-12-31 08:17:41"
}

I know the name field in the Customers model isn't well chosen, 'customer'. But I got to deal with it as at this moment we cant change it.

Any help is very welcome!

Regards, Bastiaan

Jul
04
5 months ago
Activity icon

Replied to Use Websockets In Non Vue App?

Alright, now I understand. Despite I'm not using Node I need to do npm run build so it compiles whats in /resources with Mix to /public.

Exactly what I was looking for, thanks!!

Activity icon

Replied to Use Websockets In Non Vue App?

Thanks, but /resources/js/bootstrap.js includes NodeJS functions like 'require()', not native Javascript API. So including /resources/js/bootstrap.js in my plain HTML simply wont work. But that's where I perhaps don't understand the whole architecture.

Activity icon

Started a new Conversation Use Websockets In Non Vue App?

Hello,

We use plain HTML with views, no Vue or so.

I'm implementing Laravel Websockets. The documentation describes you should add code to the /resources/js/bootstrap.js file. It looks like these files are only loaded when using Vue or so, but not with just static view pages.

import Echo from 'laravel-echo'

window.Pusher = require('pusher-js');

window.Echo = new Echo({
    broadcaster: 'pusher',
    key: window.pusherKey,
    wsHost: window.pusherHost,
    wsPort: window.pusherPort,
    disableStats: false,
    encrypted: true
});



window.Echo.channel('test')
    .listen('SendMessageToUserEvent', (e) => {
        console.log(e);
    });

How should I implement this piece of code in normal Javascipt?

Thanks in advance