devk

devk

Member Since 2 Years Ago

Experience Points
11,730
Total
Experience

3,270 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
53
Lessons
Completed
Best Reply Awards
8
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 3
11,730 XP
Sep
21
3 weeks ago
Activity icon

Started a new conversation How To Test Personal Access Token With Passport?

So I have this in my controller:

public function sendSimple(
    SimpleNotificationRequest $request
) {
    auth()
        ->user()
        ->notifications()
        ->forceCreate([
            'user_id' => auth()->id(),
            'oauth_auth_code_id' => auth()->user()->token()->id, // ??
            // ... other stuff
        ]);

    // other stuff

    return response()->success();
}

I would like to write a test for this. How do I create a Personal Access Token, so that the line with // ?? doesn't throw a FK reference error?

The Passport::actingAs(...) works for bypassing the auth middleware, but it doesn't actually set the token, so I run into the FK error.

What steps are required to actually create the Personal Access Token for the user, that will be found and set within the sendSimple method?

I've also tried this:

/** @test */
function it_can_successfully_trigger_a_simple_notification()
{
    Passport::actingAs(
        $user = factory(User::class)->create(),
        []
    );

    $client = app(ClientRepository::class)->createPersonalAccessClient(
        null, 'Test Personal Access Client', 'http://localhost'
    );

    \DB::table('oauth_personal_access_clients')->insert([
        'client_id' => $client->id,
        'created_at' => now(),
        'updated_at' => now(),
    ]);

    $token = $user->createToken('TestToken')->accessToken;

    $res = $this
        ->withHeaders([
            'Authorization' => "Bearer $token",
        ])
        ->json(
            'POST',
            '/api/v1/notifications/simple',
            // data
        );

    dd($res->getContent());
}

But I run into the same error.

Help greatly appreciated!

Aug
19
1 month ago
Activity icon

Replied to Setting SESSION_DOMAIN To Website.com For All Subdomains

Yeah probably the way I'll have to do it

Will report back if I come up with a better solution

Activity icon

Replied to Setting SESSION_DOMAIN To Website.com For All Subdomains

Nope, I don't. It's a complicated setup and complicated reasoning behind it, but I don't

The same deploy serves multiple domains (same env) and they have to act as separate sessions depending on the website.com part of the domain

Activity icon

Started a new conversation Setting SESSION_DOMAIN To Website.com For All Subdomains

Hi,

I need to set the config var SESSION_DOMAIN to the website.com even when users come from www.website.com or whatever.website.com.

How would I go about doing this?

My first thought was a simple regex in the config, parsing out the hostname. But request() isn't available yet at that point.

I'm sure it's a common enough problem that there are some reasonably nice and well tested solutions out there.

Thanks

Aug
04
2 months ago
Activity icon

Replied to ErrorException: Array_keys() Expects Parameter 1 To Be Array, Object Given

Pretty sure this is the problem:

$categorizable = [
    App\Project::class,
    App\Tip::class,
];

$categorizableType = $faker->randomElement($categorizable);
$categorizable = factory($categorizableType)->create(); // <---


return [
    // ...
    'categorizable_type' => $faker->randomElement($categorizable)
];

You reassign the $categorizable and make it an object (a model). Then you try to use it as an array in the randomElement. I indicated where you're reassigning it with // <---

Aug
02
2 months ago
Activity icon

Replied to Why Does Query Builder Add `where 1 = 0` To Empty `whereIn('col', [])` Clause?

Ah yeah, that makes sense. Didn't think about all the possibilities of where this can be used.

I can imagine that it would be extremely hard for the query builder to know whether this is used as it was in my example, or maybe it's part of an orWhere statement, where you can't just not execute the query. And I imagine it would get even harder to predict the effect if it was used in a deeply nested query.

Thanks!

Activity icon

Started a new conversation Why Does Query Builder Add `where 1 = 0` To Empty `whereIn('col', [])` Clause?

Hi,

Just noticed that when I do something like this:

\DB::enableQueryLog();
User::whereIn('id', [])->update(['updated_at' => now()]);
return \DB::getQueryLog();

The actual query is:

update `users` set `updated_at` = ? where 0 = 1

What's the reasoning behind that? Obviously, there's some check whether the passed-in array is empty. What's the benefit of executing a query with where 0 = 1 over not executing it at all?

May
30
4 months ago
Activity icon

Replied to How To Design An API For Posts, Categories And Subcategories

Like I mentioned in my original post, I don't want unique slugs. I have composite unique indexes across the slug and the foreign key

It's not that I don't know how to do any part of that, I just don't know which option will be easiest to build upon a few months down the road.

May
29
4 months ago
Activity icon

Started a new conversation How To Design An API For Posts, Categories And Subcategories

I can't decide on what's the best way to set up routes for this SQL design:

- categories
  - id
  - slug
  - parent_category_id nullable
  - (composite unique index on parent_category_id and slug)

- posts
  - id
  - slug
  - category_id
  - (composite unique index on category_id and slug)

a) I want to use slugs for querying, no ids b) I want to reliably retrieve the exact 1 post or 1 category purely by using slugs (so a post would require post's slug and it's category's slug, but category wouldn't need parent slug when fetching parent categories)

Some approaches:

  1. Split categories and subcategories. The downside being I can't query both categories and subcategories together
Route::get('categories', '[email protected]');
Route::get('categories/{slug}', '[email protected]');

Route::get('subcategories/{parentSlug}', '[email protected]');
Route::get('subcategories/{parentSlug}/{slug}', '[email protected]');

Route::get('posts/{parentSlug}', '[email protected]');
Route::get('posts/{parentSlug}/{slug}', '[email protected]');
  1. Require additional GET parameters when querying for exact post/category. The downside is obviously that without passing in additional parent slug GET parameters, I cannot reliably get the exact post/category as there's as slugs are not unique on their own
Route::get('categories', '[email protected]');
Route::get('categories/{slug}', '[email protected]');

Route::get('posts', '[email protected]');
Route::get('posts/{slug}', '[email protected]');

There are plenty of other possibilities but currently I'm leaning towards a)

It's a side project and I'm free to change whatever however I want, so if I find a better SQL solution that would work for me, I'm happy to do so instead. I just don't want ids in my urls

Thoughts, ideas?

May
24
4 months ago
Activity icon

Replied to $this->mock(..) Doesn't Mock The Interface In The Controller I'm Calling

Damn, my bad. I had an alias and was referring to the wrong interface name.

All is good and it works as expected

Activity icon

Replied to $this->mock(..) Doesn't Mock The Interface In The Controller I'm Calling

I tried that as well with the same results.

->mock(...) is just a shorthand for that (See docs)

Activity icon

Started a new conversation $this->mock(..) Doesn't Mock The Interface In The Controller I'm Calling

Hi

trying to make this work:

$this->mock(ApiContract::class, function ($mock) {
    $mock
        ->shouldReceive('getStuff')
        ->once();
});

$response = $this
    ->actingAs($user)
    ->json('POST', '/get-stuff');

If I dd(app(ApiContract::class)); after the $this->mock(..), I get an instance of Mockery as I expect it to. But if I dd(app(ApiContract::class)); from within the controller that handles /get-stuff, I still get the actual implementation as defined in my service provider.

Any idea why?

May
19
4 months ago
Activity icon

Replied to Different Output Files With Different Configs

Yeah that's what I ended up doing. Saw that mix uses let argv = require('yargs').argv; to get args passed in through package.json and ended up doing this:

mix
  .setPublicPath('./')
  .webpackConfig(sharedConfig);

if (argv.isserver) {
  mix
    .webpackConfig({
      externals: [nodeExternals()],
      node: {
        __dirname: false,
      },
    })
    .ts('node/server.tsx', './server.js');
} else {
  mix
    .copy('src/static', './public')
    .ts('src/ts/index.tsx', 'public/js/app.js');
}

Thanks!

May
18
4 months ago
Activity icon

Replied to Different Output Files With Different Configs

As the next best thing is it possible to get node env variables within the webpack.mix.js?

Something like this would work well enough:

const sharedConfig = {
  // Shared config
};

if (!process.env.isserver) {
  mix
    .setPublicPath('./')
    .webpackConfig(sharedConfig)
    .copy('src/static', './public')
    .ts('src/ts/index.tsx', 'public/js/app.js');  
} else {
  mix
    .setPublicPath('./')
    .webpackConfig({
      ...sharedConfig,
      externals: [nodeExternals()],
      node: {
        __dirname: false,
      },
    })
    .ts('node/server.tsx', './server.js');  
}

But I can't get this to work either. It doesn't read any variables I pass to the script

Activity icon

Started a new conversation Different Output Files With Different Configs

What's the best way to compile 2 JS files that require different configs? Namely, my server config requires some additional config options from my regular frontend config.

This is basically what I'm trying to do (spoiler, it doesn't work because the 2nd config is applied to the client side as well:

const sharedConfig = {
  // Shared config
};

mix
  .setPublicPath('./')
  .webpackConfig(sharedConfig)
  .copy('src/static', './public')
  .ts('src/ts/index.tsx', 'public/js/app.js');

mix
  .setPublicPath('./')
  .webpackConfig({
    ...sharedConfig,
    externals: [nodeExternals()],
    node: {
      __dirname: false,
    },
  })
  .ts('node/server.tsx', './server.js');
Mar
25
6 months ago
Mar
24
6 months ago
Activity icon

Replied to Mockery `->with(SomeModel)` Returns Fails

Hmm no, they're not the same instance. The DB call happens in the service, any thoughts on how I should approach this?

Thanks for the explanation @staudenmeir!

Mar
22
6 months ago
Activity icon

Started a new conversation Mockery `->with(SomeModel)` Returns Fails

Hi,

I have a test like that :

$model = factory(SomeModel::class)->create()->fresh();

SomeService::shouldReceive('cancel')
    ->with($model)
    ->once();

and it always fails saying that passed in $model is not the same as the expected $model I've dumped them, compared attributes and they're the same. I've added ->fresh() to my factory to load the default attributes. I've also tried getting the $model with a new query $bet = Model::find($model->id);. The test always fails.

There are no changes made to the model before the cancel function in the SomeService.

Any help appreciated!

Mar
06
7 months ago
Activity icon

Started a new conversation How To Scope BelongsTo Field To Only Return A Subset

Hi,

I have a categories table with parent_id that refers to the same table. For reference, the relationship will only have 2 levels (parent and children), but that doesn't matter for this question.

So in my Category Nova resource, I have something like this:

// ...
BelongsTo::make('Parent', 'parent', 'App\Nova\Category')
    ->sortable()
    ->nullable(),
// ...

Is it possible to scope the results of this to only parent relationships, basically adding this: ->whereNull('parent_id')?

I'm aware I can make a new relationship and add a scope there, but I would prefer to do it in the Nova resource as it wouldn't be used anywhere else in the project.

Thanks!

Jan
17
8 months ago
Activity icon

Started a new conversation What's `->using(Pivot::class)` ?

I see there's a ->using(Pivot::class) method on the belongsToMany relationship, which supposedly sets the Pivot model to use in the relationship. What does that effect?

Thanks in advance!

Jan
01
9 months ago
Activity icon

Replied to Polymorphic Relationship With 2 Different ID Columns

Bumping. NYE probably wasn't the best time to ask.

Dec
31
9 months ago
Activity icon

Started a new conversation Polymorphic Relationship With 2 Different ID Columns

Hi,

I needed a polymorphic table for storing metadata, but my project has both UUIDs (binary) and IDs (uint). So I added both an uint and a binary id column and added a very hacky check for (which works for my needs so far) which one the relation should use .

Can this bite me in the ass in some way I didn't foresee and, if so, would you recommend another way:

<?php

namespace App\Traits\Model;

use App\Models\Metadata;

trait Metadatable
{
    public function metadata()
    {
        return $this->morphMany(
            'App\Models\Metadata',
            'metadatable',
            'metadatable_type',
            app(self::class)->getKeyName() === 'uuid'
                ? 'metadatable_uuid'
                : 'metadatable_id'
        );
    }
}

Thanks and happy new year!

Dec
10
10 months ago
Activity icon

Replied to Disable DB Unique Checks For Tests

@TYKUS - Nice, thanks for the suggestion! Will look into it

Just the addition of ->afterCreatingState(..) saved me a ton of headaches, but there are still some problems that faker/factories don't help me solve (such as checking for complicated uniqueness across multiple columns or when creating multiple models)

Activity icon

Replied to Disable DB Unique Checks For Tests

@REALRANDYALLEN - Hmm interesting, but this does indeed seem to work (unless I got lucky 10 times in a row).

Thanks!

Activity icon

Replied to Disable DB Unique Checks For Tests

It's pretty complicated as there's a chain of factories being called and faker's ->unique() has no way of checking for uniqueness when creating multiple models at once.

Properly fixing the factories could easily take days and I'll do it when I have some spare time, which is not now.

Activity icon

Started a new conversation Disable DB Unique Checks For Tests

Hi,

I want to disable unique checks when running tests. I have some poorly set up factories that I don't have time to fix and they sometimes generate records that don't agree with the unique checks.

I tried this:

public function setUp()
{
    parent::setUp();
    \DB::statement('SET UNIQUE_CHECKS=0;');
}

with no luck.

Any help greatly appreciated, thanks!

Nov
07
11 months ago
Activity icon

Replied to [BUG] Going Back Returns JSON

Can confirm it doesn't happen on Firefox either.

From my testing it only happens on Chrome. It's updated to the latest version (it's not in my screenshot, but I've updated since) and it consistently gives me same bug.

Let me know if I can assist debugging this in any way.

Activity icon

Replied to [BUG] Going Back Returns JSON

Tested in Safari. Cannot reproduce.

But in Chrome I consistently get the same problem on my threads. Other threads do not produce the same bug.

Activity icon

Replied to [BUG] Going Back Returns JSON

See my edit. I narrowed it down more

Activity icon

Started a new conversation [BUG] Going Back Returns JSON

How to reproduce:

  1. Launch Chrome
  2. Go to a thread you created
  3. click on any link (can also be an external link)
  4. click back
  5. get JSON for with the thread data - Screenshot

Edit:

It seems to only trigger on the thread that I created. Incognito does not reproduce the same bug on the same thread, but going to a different thread I created does

Nov
06
11 months ago
Activity icon

Replied to Additional Data On Default Laravel Auth Events

Yeah the listeners might (will probably) be async, so I can't use request().

So currently I see 2 other, not too terrible, options:

  1. My original idea of listening to Illuminate\Auth\Events\Login with a sync listener and just triggering a custom event with the cookie data from the listener
  • Pro: the even would be explicit, easy to read
  • Con: seems super stupid to add an extra chain of event-listener in this cycle
  1. Your suggestion of handling this with cache
  • Pro: straightforward implementation
  • Con: seeing just the listener and the event, reader of the code would have a problem understanding what the Cache calls are doing, what is getting returned and especially where it's getting set

I'll sleep on it, see if someone has a better idea

Activity icon

Replied to Additional Data On Default Laravel Auth Events

That would work. But it doesn't seem as verbose as having an event with the required properties set to public. Or implementing an interface with getters for the cookie data.

Activity icon

Started a new conversation Additional Data On Default Laravel Auth Events

Hi, I'm trying to make use of specifically the Illuminate\Auth\Events\Login event. It works great out of the box, but I need access to some additional data on my listeners, specifically from some cookies at the time of login.

What would be a good way of saving data from a cookie and have it available in listeners attached to Illuminate\Auth\Events\Login event? Even to queued listeners that do not have access to the request.

I was thinking, if there was a way to override this specific method: fireLoginEvent() (source) that would work. But I don't think there is. The class implements Macroable so I tried creating a macro named fireLoginEvent, but it doesn't override the implemented method.

Any other ideas? I would like to avoid creating a listener on the native event that would just trigger a new custom event for my case.

Thanks in advance

Nov
05
11 months ago
Activity icon

Replied to When Does The `report()` Method Of An Exception Get Called?

It gets reported upon throwing the exception.

Here's how I tested it (Tinker seems to catch all exceptions I guess):

Route::get('/', function () {
    $a = new \App\Exceptions\TestException('test');
    info('here we are');
    throw $a;
});

and the exception:

<?php

namespace App\Exceptions;

use Exception;

class TestException extends Exception
{
    public function report()
    {
        info('reported!!');
    }
}

And the laravel.log after visiting /:

[2018-11-05 17:22:04] local.INFO: here we are

[2018-11-05 17:22:05] local.INFO: reported!!

Edit:

As another interesting note, the report() method does not get called on caught exceptions.

Activity icon

Started a new conversation When Does The `report()` Method Of An Exception Get Called?

Hi,

I'm wondering when does the report() method on an exception get called?

Say that we have this code:

$a = new SomeCustomException(..);
dump('we\'re here');
throw $a;

Will the report() get called upon instantiating the exception or when the exception gets thrown?

Also I tried putting simple info('test'); into report() method of a custom exception and a) instantiate it in tinker b) throw it in tinker and it didn't log my 'test'. I'm thinking it only works on requests probably.

Nov
01
11 months ago
Oct
31
11 months ago
Activity icon

Replied to Eloquent Resource `whenLoaded` Does Not Work As Expected Within `with` Method

This is my temporary solution:



    /**
     * Get additional data that should be returned with the resource array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function with($request)
    {
        if (! Auth::check() || ! $this->relationLoaded('user_picks')) {
            return [];
        }

        return [
            'meta' => [
                'user_picks' => OutcomeResource::collection(
                    $this->user_picks
                ),
            ],
        ];
    }
Activity icon

Started a new conversation Eloquent Resource `whenLoaded` Does Not Work As Expected Within `with` Method

Hi,

here's the code I'm trying to make work:

<?php

namespace App\Http\Resources;

class ModelResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'user_picks' => AnotherModelResource::collection(
                $this->whenLoaded('user_picks')
            ),
        ];
    }

    /**
     * Get additional data that should be returned with the resource array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function with($request)
    {
        if (! auth()->check()) {
            return [];
        }

        return [
            'meta' => [
                'user_picks' => AnotherModelResource::collection(
                    $this->whenLoaded('user_picks')
                ),
            ],
        ];
    }
}

I'm trying to make the logic in with(..) method work (I want to load user_picks under meta and only when a user is logged in + the relation has been eagerly loaded). It's only replicated in the toArray() part because I wanted to double check if the same functionality works there. It does.

So - the toArray() part works perfectly, but the with() part dies when the relationship was not eagerly loaded with the next error:

testing.ERROR: Trying to get property 'map' of non-object {"exception":"[object] (ErrorException(code: 0): Trying to get property 'map' of non-object at ./vendor/laravel/framework/src/Illuminate/Http/Resources/Json/ResourceCollection.php:48) [stacktrace]

Any help appreciated, thanks!

Oct
26
11 months ago
Activity icon

Replied to How To Tell If A Request Is Made To The API Routes

Yeah that seems good. For my use case, I think I'll actually settle for ! $request->hasSession() + (||) your suggestion.

Thanks!

Activity icon

Started a new conversation How To Tell If A Request Is Made To The API Routes

Hi, so I'm trying to implement the render method of an Exception, but since I use the exception in both api routes and stateful routes, I need to be able to tell if it's api or not.

I could just check the first segment of the URL, but seems hacky. Maybe there's a way to check if the request went through api middleware? Or anything even more straightforward?

Thanks

Oct
25
11 months ago
Activity icon

Started a new conversation Model Update Method That Would Return Updated Model

Hey

simple, code style question.

How would I make this a 1 liner:

public function update(Request $request, int $id)
{
       return new ModelResource(
            Model::findOrFail($id)->update($request->input())
       );
}

This doesn't work as ->update(..) returns a boolean. I also tried ->fill(..)->save(), but ->save() also returns a boolean.

Any suggestions, ideas? Is it possible?

Thanks!

Sep
21
1 year ago
Activity icon

Replied to Storing Additional Data With A Request

@D9705996 Yeah that's pretty much perfect! Also, I used 3 other Spatie (Fractal, UUIDs, QueryBuilder) packages in the same project - have a lot of trust in their packages. The annoying part is generally just updating lots of packages and going through all the changelogs and making sure nothing breaks.

@Cronix Yeah that also seems like a great solution.

Activity icon

Replied to Storing Additional Data With A Request

@D9705996 Interesting, will look into it. Though, I would prefer not to add another dependency for such a small thing.

@Cronix I'm using this on stateless api routes.

Activity icon

Started a new conversation Storing Additional Data With A Request

So, I have a middleware that queries for a model with passed in api key. Similar to auth middleware.

Now, I don't want to query for that model again in my controller methods.

So currently I do this: $request['model'] = $model; and retrieve it with $request->model.

My question is if there's a better way of achieving this. I'm not a fan of that attribute being treated as input (it can also be retrieved with ->input('model'), which it clearly isn't.

Thanks in advance!

May
03
1 year ago
Activity icon

Started a new conversation Model Factory That Would Create Related HasMany Models As Well

I'm looking for a way to create related hasMany models on the parent factory. Is that possible?

An example: a user can have many mails and possibly some other ->hasMany relations.

For my tests it would be extremely useful if I could define a factory for a user with a) with multiple mails b) a mail that is confirmed (column on mail model) c) ...

I'm looking for something along these lines:

$factory->defineAs(User::class, 'with_mail', function (Faker $faker) {
    $user = factory(User::class)->create();
    $mail = factory(UserMail::class)->create([
        'user_id' => $user->id,
    ]);
    return $user;
});

This doesn't work as the defineAs method expects to have raw attributes returned, but obviously, if I don't ->create() a user (but ->make() it instead), I can't assign them an email.

Is there a way to accomplish this with Eloquent factories?

Apr
26
1 year ago
Activity icon

Replied to Retrieving Multiple Table Rows With Common Column

Are you sure you want a join here? Seems like you might want union instead.

This happens because container_id (and probably some other fields as well) is ambiguous.

Is the desired result to get data from all 3 tables in separate rows, or do you expect every row to have data from all 3 tables?

Activity icon

Replied to Creating Non Reactive Copies Of Vue Data

Or just Object.assign(this.oldForm, this.form). Or this.oldForm = {...this.form}.

Apr
25
1 year ago
Activity icon

Replied to Trying To Get Property Of Non-object - Default Fallback

Probably not the best idea if you're not desperate. But you could override the getRelationValue($key) method with something like this:

public function getRelationValue($key)
{
    return parent::getRelationValue($key) ?? optional();
}

optional() will return null when you call some property on it. Of course, you could return some custom object that returns 'non-object data' on all properties (or implements __toString()with the text and returns itself recursively on property call) instead, but you get the idea.

Activity icon

Replied to Trying To Get Property Of Non-object - Default Fallback

That's beautiful. I had no idea that doesn't throw an error.