kevinbui

kevinbui

Full Stack Developer at Bitcoin Australia

Member Since 5 Years Ago

Melbourne, Australia

Experience Points
62,270
Total
Experience

2,730 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
505
Lessons
Completed
Best Reply Awards
21
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 13
62,270 XP
Feb
17
5 days ago
Activity icon

Replied to Eager Loading With 1 Constraint For Multiple Model

Lets create a new Trait that contains a local scope:

namespace App\Traits;

trait CreatedWithinTimeRange
{
     /**
      * @param  \Illuminate\Database\Eloquent\Builder  $query
      * @param string|\Carbon\Carbon $firstDate
      * @param string|\Carbon\Carbon $secondDate
      * @return \Illuminate\Database\Eloquent\Builder
      */
    public function scopeCreatedWithin(Builder $query, $firstDate, $endDate)
    {
        return $query->whereBetween('created_at', $firstDate, $endDate);
    }
}

Then, you can add the trait in both Book and Publisher classes:

class Author extends Model
{
    use CreatedWithinTImeRange;
}

class Publisher extends Model
{
    use CreatedWithinTImeRange;
}

Finally, you can rewrite your query like:

$date1 = Carbon::parse('2020-02-15 00:00:00');
$date2 = Carbon::parse('2020-02-18 23:59:59');

$books = App\Book::with(['author' => function ($query) use ($date1, $date2) {
    $query->createdWithin($date1, $date2);
}, 'publisher' => function ($query) use ($date1, $date2) {
    $query->createdWithin($date1, $date2);
}] )->get();

Feb
16
6 days ago
Activity icon

Awarded Best Reply on Display Specific Values ​​in Relation

I think you are talking about Nova. I check the Laravel Nova docs and it seems that you can override the title() function to customise the display.

public function title()
{
    return “{$this->name} {$this->surname}”;
}
Feb
15
1 week ago
Activity icon

Awarded Best Reply on How To Fetch Count From Distant Relationship?

I believe that you want to have the number of products for each attribute with a specific category, don't I?

If I am correct. You can do something like this:

$categoryId = 9;

$attributes = Attribute::withCount(['products' => function ($query) use ($categoryId) {
    $query->whereHas('categories', function ($query) use ($categoryId) {
        $query->whereKey($categoryId);
    })
}])->get();

Then, you can access the number of products for each attribute:

@foreach($attributes as $attribute)
    <p>{{$attribute->products_count}}</p>
@endforeach
Activity icon

Replied to Children, Children, Parents.

You want to give an example for that?

Activity icon

Replied to Laravel Check Record If Exist Throw Exception

Instead of is_null(), you can use empty().

Activity icon

Replied to $request->user() Vs Auth()->user() Vs Auth::user()

@eco012390 Out of curiosity, why do want to know that?

I am sure that the difference is not significant.

Feb
14
1 week ago
Activity icon

Replied to Display Specific Values ​​in Relation

I think you are talking about Nova. I check the Laravel Nova docs and it seems that you can override the title() function to customise the display.

public function title()
{
    return “{$this->name} {$this->surname}”;
}
Activity icon

Awarded Best Reply on Loop Through Query Items Before Paginating

What about paginating the query to get the results, and then add an extra attribute to each of the model instance:

$results = DB::table(...)
    ->where(...)
    ->paginate()
    ->each(function ($record) {
        $record->setAttribute('score', 'some_score');
    })
Activity icon

Awarded Best Reply on NewQuery In User Model

Why does it fail? What error message do you have?

Also, I feel like it would be proper to add a global scope instead of extending newQuery function.

Activity icon

Replied to How To Plan And Prepare A Project?

If you code for fun or work with your side projects then just do it.

If you are more serious with your ideas then I think getting real by Base Camp is a pretty good guide.

To write clean code, check out Laracasts videos and the clean code book by Uncle Bob Martin.

Activity icon

Replied to How To Fetch Count From Distant Relationship?

I believe that you want to have the number of products for each attribute with a specific category, don't I?

If I am correct. You can do something like this:

$categoryId = 9;

$attributes = Attribute::withCount(['products' => function ($query) use ($categoryId) {
    $query->whereHas('categories', function ($query) use ($categoryId) {
        $query->whereKey($categoryId);
    })
}])->get();

Then, you can access the number of products for each attribute:

@foreach($attributes as $attribute)
    <p>{{$attribute->products_count}}</p>
@endforeach
Feb
13
1 week ago
Activity icon

Replied to NewQuery In User Model

Why does it fail? What error message do you have?

Also, I feel like it would be proper to add a global scope instead of extending newQuery function.

Activity icon

Replied to Laracasts Quizzes

I check the documentation. @enderrors doesn't exist.

Activity icon

Replied to Laracasts Quizzes

@jeffreyway I found a small typo for question no. 9. It got to be @enderror instead of @enderrors.

I was confused and missed that question.

Activity icon

Replied to Loop Through Query Items Before Paginating

What about paginating the query to get the results, and then add an extra attribute to each of the model instance:

$results = DB::table(...)
    ->where(...)
    ->paginate()
    ->each(function ($record) {
        $record->setAttribute('score', 'some_score');
    })
Feb
12
1 week ago
Activity icon

Replied to Get Data From Multiple Models

A common trick is to use organizations as a PIVOT table for a MANY TO MANY relationship between users and groups.

class User extends Model
{
    public function organizations()
    {
        return $this->hasMany(Organization::class);
    }

    public function groups()
    {
        return $this->belongsToMany(Group::class, 'organizations')
            ->withPivot('id', 'name');
    }
}

Now, you can get everything in one go by saying:

User::with('groups')->get();
Activity icon

Awarded Best Reply on Many To Many - Get Data From Pivot (included Other Models That Share Same Id)

You can say:

$user->groups()->with('users')->get();

Or you can also say:

// I assume you already define a users() relationship in your Group model.
Group::with('users')->whereHas('users', function ($query) use ($user) {
    return $query->whereKey($user->id);
})
->get();
Activity icon

Replied to Many To Many - Get Data From Pivot (included Other Models That Share Same Id)

You can say:

$user->groups()->with('users')->get();

Or you can also say:

// I assume you already define a users() relationship in your Group model.
Group::with('users')->whereHas('users', function ($query) use ($user) {
    return $query->whereKey($user->id);
})
->get();
Feb
04
2 weeks ago
Activity icon

Replied to How To Get Data In Join Table To Show

What are you trying to achieve? Your code looks fine.

Activity icon

Replied to Problem With Trait And Fillable

Does it work if you remove the Images trait from that class? If possible, can you post the code for the Images trait too?

Activity icon

Replied to Laravel Has Many Through Relation

You want to check the documentation to make sure that you set correct foreign keys and local keys for hasManyThrough function?

Activity icon

Replied to Unable To Use Mutators On HasManythrough() Relation Sum Function

I believe this is what you want to achieve:

class Campaign extends Model
{
    public function customer() 
    {
        return $this->belongsTo(Customer::class);
    }

    // Rename the relationship to be plural.
    public function accountReceivables()
    {
         return $this->hasManyThrough(AccountReceivable::class, CampaignMedium::class);
    }

    public function getPaymentTotalsAttribute()
    {
        return $this->accountReceivables->sum('amount');
    }
}

You don't need the receivedPayments relationship. Group by campaign_id within the Campaign class doesn't make sense. Also, I doubt that it become snake cased and overrides your getReceivedPaymentsAttribute when returning the data.

Then inside the controller:

public function all()
{
    return Campaign::with('accountReceivables')
        ->append('payments_total')
        ->get();
}

laravel_through_key is added with the Has Many Through relationship. It will be gone with my proposed solution.

Activity icon

Replied to Updating Models Within A Collection (without Saving To The Db)

You want to highlight your code blocks first so people can understand your code?

Feb
03
2 weeks ago
Activity icon

Awarded Best Reply on Laravel Many To One Same Table Migration

I believe your migration got to be modified to something like this:


saidu
•
4 hours ago
28
0
GENERAL
Laravel many to one same table migration
I have this code for migration

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateFixturesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('fixtures', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedInteger('home_team_id');
            $table->unsignedInteger('away_team_id');
            $table->string('date');
            $table->string('field');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('fixtures');
    }
}

Then in the model:

namespace App;

use Illuminate\Database\Eloquent\Model;

class Fixture extends Model
{
    //
    protected $fillable = [
        'home_team_id',
        'away_team_id',
        'date',
        'field'
    ];

    public function homeTeam()
    {
        return $this->belongsTo('App\Team', 'home_team_id');
    }

    public function awayTeam()
    {
        return $this->belongsTo('App\Team', 'away_team_id');
    }
}
Feb
02
2 weeks ago
Activity icon

Replied to Reading Import Excel

I don't understand your question? You want to clarify that?

Activity icon

Replied to Adding Dynamic Fields

I believe this is what you want to achieve:

namespace App\Imports;

use App\User;
use Maatwebsite\Excel\Concerns\ToModel;
use Maatwebsite\Excel\Concerns\WithBatchInserts;

class UsersImport implements ToModel, WithBatchInserts
{
    public function model(array $row)
    {
        if (User::where($row)->exists()) {
            return null;
        }
        
        return new User($row);
    }
}

According to the documentation, you can also do this:

namespace App\Imports;

use App\User;
use Maatwebsite\Excel\Row;
use Maatwebsite\Excel\Concerns\OnEachRow;

class UsersImport implements OnEachRow
{
    public function onRow(Row $row)
    {
        User::firstOrCreate($row->toArray());
    }
}
Activity icon

Replied to Laravel Many To One Same Table Migration

I believe your migration got to be modified to something like this:


saidu
•
4 hours ago
28
0
GENERAL
Laravel many to one same table migration
I have this code for migration

<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateFixturesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('fixtures', function (Blueprint $table) {
            $table->bigIncrements('id');
            $table->unsignedInteger('home_team_id');
            $table->unsignedInteger('away_team_id');
            $table->string('date');
            $table->string('field');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('fixtures');
    }
}

Then in the model:

namespace App;

use Illuminate\Database\Eloquent\Model;

class Fixture extends Model
{
    //
    protected $fillable = [
        'home_team_id',
        'away_team_id',
        'date',
        'field'
    ];

    public function homeTeam()
    {
        return $this->belongsTo('App\Team', 'home_team_id');
    }

    public function awayTeam()
    {
        return $this->belongsTo('App\Team', 'away_team_id');
    }
}
Activity icon

Replied to Foreach Loop

I missed a semicolon inside the filter() function. I have updated answer.

Feb
01
3 weeks ago
Activity icon

Replied to Combining Multiple HasManyThrough Outputs

Cool, that definitely works. I want to propose a few other alternatives that could be a bit cleaner and more performant.

And I don't think hasManyThrough is gonna work though. There are not multiple layers of hasMany relationships in this scenario.

SOLUTION 1:

You might create a Many To Many relationships between resellers and customers, taking advantage of the domain_registrations and webhosting_accounts table. Then

class Reseller extends Model
{
    public function drCustomers()
    {
        return $this->belongsToMany(Customer::class, 'domain_registrations');
    }

    public function waCustomers()
    {
        return $this->belongsToMany(Customer::class, 'webhosting_accounts');
    }

    public function getCustomers()
    {
        return $this->drCustomers
            ->merge($this->waCustomers)
            ->unique();
    }
}

SOLUTION 2:

You might use Many To Many polymorphic relationships. For this, the database got to be redesigned:

domain_registrations:
- id
- domain
- ...

webhosting_accounts:
- id
- domain
- ...

serviceables:
- id
- reseller_id
- customer_id
- serviceable_id
- serviceable_type
- ...

customers:
- id
- name
- ...
// This is not important, just to give an idea how your models will work with the new design.
class DomainRegistration extends Model
{
    public function customers()
    {
        return $this->morphToMany(Customer::class, 'serviceable');
    }
}

class WebhostingAccount extends Model
{
    public function customers()
    {
        return $this->morphToMany(Customer::class, 'serviceable');
    }
}

class Customer extends Model
{
    public function domainRegistrations()
    {
        return $this->morphedByMany(DomainRegistration::class, 'serviceable');
    }
    public function webhostingAccounts()
    {
        return $this->morphedByMany(WebhostingAccount::class, 'serviceable');
    }
}

Then from the reseller, you can simply say:

class Reseller extends Model
{
    public function customers()
    {
        // Got to call distinct() because serviceables table will contain duplicate pairs of reseller_id and customer_id.
        return $this->belongsToMany(Customer::class, 'serviceables')->distinct();
    }
}
Activity icon

Replied to Laravel Testing

To be more specific, I recommend starting with building a forum in Laracasts. Its pretty basic and easy to follow.

Test Driven Laravel is a lot more advanced, and it's pricey too. Still recommended, but maybe you finish the first course I mentioned first.

Jan
31
3 weeks ago
Activity icon

Replied to Combining Multiple HasManyThrough Outputs

Can you post your database structure for those tables?

Activity icon

Replied to Foreach Loop

I will define a new function to get all service attributes for a package:

use Illminate\Support\Str;

class Package extends Model
{
    public function packages()
    {
        return collect($this->getAttributes())
            ->filter(function ($value, $key) {
                return Str::startsWith($key, 'offered_service_');
            })
            ->all();
    }
}

So in the view I can say:

@foreach ($packages as $package)
    <ul>
        <h2>{{ $package->title }}</h2>
        @foreach ($package->services() as $service)
            <li>{{ $service }}</li>
        @endforeach
    </ul>
@endforeach
Activity icon

Replied to Get Specific Items From Relationship In Model

Your solution is fine. I personally prefer to create a query scope for that:

class Event extends Model
{   
    public function scopeOnDate($query, $date)
    {
        return $query->whereDate('start_date', '=', Carbon::parse($date)->format('Y-m-d'));
    }
}

So it can be rewritten in User model:

class User extends Model
{
    public function eventsScheduledFor($date)
    {
        return $this->events()->onDate($date)->get();
    }
}

Activity icon

Awarded Best Reply on Import CSV + Form Inputs To Same Mysql Table.

Because you can access the request object any where in your project. This may work:

class CsvImport implements ToModel
{
    
    public function model(array $row)
    {
        return new Computer([
            'first_name' => $row[0],
            'last_name' => $row[1],
            'asset_tag' => $row[2],
            'pc_name' => request('pc_name');
        ]);

    }
}

Or, you can pass the pc name to the CsvImport instance.

class CsvImport implements ToModel
{
    protected $pcName;

    public function __construct(string $pcName) 
    {
        $this->pcName = pcName;
    }
    
    public function model(array $row)
    {
        return new Computer([
            'first_name' => $row[0],
            'last_name' => $row[1],
            'asset_tag' => $row[2],
            'pc_name' => $this->pcName;
        ]);

    }
}

Then in your controller:

public function csv_import(Request $request) {
        Excel::import(
            new CsvImport($request->input('pc_name')), 
            $request->file('file')
        );

        return back();
    }
Activity icon

Replied to Import CSV + Form Inputs To Same Mysql Table.

Because you can access the request object any where in your project. This may work:

class CsvImport implements ToModel
{
    
    public function model(array $row)
    {
        return new Computer([
            'first_name' => $row[0],
            'last_name' => $row[1],
            'asset_tag' => $row[2],
            'pc_name' => request('pc_name');
        ]);

    }
}

Or, you can pass the pc name to the CsvImport instance.

class CsvImport implements ToModel
{
    protected $pcName;

    public function __construct(string $pcName) 
    {
        $this->pcName = pcName;
    }
    
    public function model(array $row)
    {
        return new Computer([
            'first_name' => $row[0],
            'last_name' => $row[1],
            'asset_tag' => $row[2],
            'pc_name' => $this->pcName;
        ]);

    }
}

Then in your controller:

public function csv_import(Request $request) {
        Excel::import(
            new CsvImport($request->input('pc_name')), 
            $request->file('file')
        );

        return back();
    }
Jan
28
3 weeks ago
Activity icon

Awarded Best Reply on Validating Array Item With Rule Class

I have just solved a somewhat similar problem with validation. I think when we need to apply a COMPLEX validation rule that involves MULTIPLE attributes in the same request, an after hook can be implemented:

class YourRequest extends FormRequest
{
    public function withValidator($validator)
    {
        $validator->after(function ($validator) {
            foreach ($this->input('line_items') as $index => $lineItem) {
                if ($lineItem->userProduct->is_template_product && ! Arr::get($lineItem, 'image_name')) {
                    $validator->errors()->add("line_items.{$index}.image_name", 'Image name is required.');
                }    
            }
        });
    }

    public function rules()
    {
        return [
            // ...
        ];
    }
}
Jan
23
4 weeks ago
Activity icon

Awarded Best Reply on Getting A List Of Items From Eloquent

This could be a good use case for Morph To Many Polymorphic relationship

class User extends Model
{
    public function favouritedEvents()
    {
        return $this->morphedByMany(Event::class, 'favourited', 'favourites');
    }
}
Activity icon

Replied to Getting A List Of Items From Eloquent

@chrisgrim Does that table named "favourites". I have updated my answer. The third param is the name of the favourites table. Pls check.

Jan
22
1 month ago
Activity icon

Replied to Does This Count As A Example Of N+1 Query And Can It Be Improved?

Can I see LoanRetrievalServices::getNextPayDate() function?

Activity icon

Replied to Getting A List Of Items From Eloquent

This could be a good use case for Morph To Many Polymorphic relationship

class User extends Model
{
    public function favouritedEvents()
    {
        return $this->morphedByMany(Event::class, 'favourited', 'favourites');
    }
}
Activity icon

Awarded Best Reply on Inception Of Relationships Between Models

A slightly more performant approach could be:

return $this->loadMissing('products.categories')
    ->products
    ->map->categories
    ->collapse()
    ->unique('id')
    // Do this step if you want a Illuminate\Database\Eloquent\Collection instead of an Illuminate\Support\Collection.
    ->pipe(function ($categories) {
        return new Illuminate\Database\Eloquent\Collection($categories->all());
    });

I rarely use flatMap. But maybe this can also work.

return $this->loadMissing('products.categories')
    ->products
    ->flatMap
    ->categories
    ->unique('id')
Jan
21
1 month ago
Activity icon

Replied to Laravel Relationship BelongsTo Not Working

You are using a plural form for the relationship function (users). Is that BelongsTo, or HasMany would be more proper?

Activity icon

Replied to Inception Of Relationships Between Models

A slightly more performant approach could be:

return $this->loadMissing('products.categories')
    ->products
    ->map->categories
    ->collapse()
    ->unique('id')
    // Do this step if you want a Illuminate\Database\Eloquent\Collection instead of an Illuminate\Support\Collection.
    ->pipe(function ($categories) {
        return new Illuminate\Database\Eloquent\Collection($categories->all());
    });

I rarely use flatMap. But maybe this can also work.

return $this->loadMissing('products.categories')
    ->products
    ->flatMap
    ->categories
    ->unique('id')
Activity icon

Replied to Validating Array Item With Rule Class

I have just solved a somewhat similar problem with validation. I think when we need to apply a COMPLEX validation rule that involves MULTIPLE attributes in the same request, an after hook can be implemented:

class YourRequest extends FormRequest
{
    public function withValidator($validator)
    {
        $validator->after(function ($validator) {
            foreach ($this->input('line_items') as $index => $lineItem) {
                if ($lineItem->userProduct->is_template_product && ! Arr::get($lineItem, 'image_name')) {
                    $validator->errors()->add("line_items.{$index}.image_name", 'Image name is required.');
                }    
            }
        });
    }

    public function rules()
    {
        return [
            // ...
        ];
    }
}
Jan
10
1 month ago
Activity icon

Awarded Best Reply on ToArray With MorphOne

You got to manually access to address first for the model to got the address relation:

Business::with('address')->get();

$business->address;

$business->load('address');

$business->loadMissing('address');

If you want to always include address for serialisation, please include it in the $with array:

class Business extends Model {
   protected $with = ['address'];

   public function address()
   {
       return $this->morphOne('App\Address','imageable');
   }
}

later on, you can occasionally exclude the address relation:

Business::without('address')->get();
Jan
08
1 month ago
Activity icon

Replied to How Do I Paginate My Activity Feed Relationship In A JSON Resource API?

What about updating your relationships like this:

class User extends Model
{
    public function activity()
    {
        return $this->hasMany('App\Activity');
    }
    
    public function latestActivity()
    {
        return $this->hasOne('App\Activity')->latest();
    }
}

So you can use both activity and latestActivity.

Activity icon

Replied to ToArray With MorphOne

You got to manually access to address first for the model to got the address relation:

Business::with('address')->get();

$business->address;

$business->load('address');

$business->loadMissing('address');

If you want to always include address for serialisation, please include it in the $with array:

class Business extends Model {
   protected $with = ['address'];

   public function address()
   {
       return $this->morphOne('App\Address','imageable');
   }
}

later on, you can occasionally exclude the address relation:

Business::without('address')->get();
Activity icon

Replied to Laravel Policies

I believe this piece of code:

array_intersect($user->roles->pluck('name')->toArray(), [])

It is gonna return an empty array. So the policy check will eventually return false.

Jan
07
1 month ago
Activity icon

Replied to Add Loader To Website While Axios Is Getting Data

vueschool.io got a chapter about this. The idea is pretty straightforward.

<ul v-if="dataNotEmpty">
    // Show the data list.
</ul>
<loader v-else/>

If you are using React, please check out React Suspense.

It is not official. But I heard that in the upcoming Vue 3 will have a similar mechanism like React Suspense.