How to create a component and add it to Blade in Laravel?

Go to you app.js file “resources\js\app.js” and add this:

Vue.component('view-dashboard-component', () => import('./components/Admin/Navbar/DashboardComponent.vue'));

Make sure you create 2 vue folders called “Admin/Navbar/” inside the components vue folder in “resources\js\components”

In your vue file add this:


Just above this:

const app = new Vue({
    el: '#app',
});

Now create a Laravel view blade file, and add this in it:

resources\views\admin\dashboard\index.blade.php
@extends('layouts.app')

@section('content')
    
@endsection

To get to this file, create a route in your “routes\web.php” and add this:

    Route::get('/admin/dashboard', 'Admin\DashboardController@index');

In your controller make sure you have this:

public function index() {
return view('admin.dashboard.index');
}

Now type your domain as:

www.mydomain.com/admin/dashboard

and you should see your component

Enjoy!

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Disclaimer:

As an Amazon Associate I earn from qualifying purchases. This post may contain affiliate links which means I may receive a commission for purchases made through links.