PHPackages                             yudhees/laravel-vue-controller - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. yudhees/laravel-vue-controller

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

yudhees/laravel-vue-controller
==============================

To Access Laravel Controller Inside a vue file

1.5(2y ago)115MITPHPPHP &gt;=4.0.0

Since Mar 4Pushed 2y ago1 watchersCompare

[ Source](https://github.com/yudhees/laravel-vue-Controller)[ Packagist](https://packagist.org/packages/yudhees/laravel-vue-controller)[ RSS](/packages/yudhees-laravel-vue-controller/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (1)Dependencies (2)Versions (3)Used By (0)

laravel-vue-controller - To access your controller within a vue file
--------------------------------------------------------------------

[](#laravel-vue-controller---to-access-your-controller-within-a-vue-file)

Note

Welcome To laravel-vue-controller , I request you to read the below documentation clearly

Installation
------------

[](#installation)

Composer
--------

[](#composer)

```
 composer require yudhees/laravel-vue-controller

```

or
--

[](#or)

Begin by installing this package through Composer. Edit your project's `composer.json` file to require `yudhees/laravel-vue-controller`.

```
"require-dev": {
     "yudhees/laravel-vue-controller": "1.5"
}

```

Next, update Composer from the Terminal:

```
composer update

```

Note

if You are using Laravel &gt; 4 Skip the below step because The service provider is auto discover then no need to register this provider

Laravel &lt;=4
--------------

[](#laravel-4)

Once this operation completes, the final step is to add the service provider. Open `config/app.php`, and add a new item to the providers array.

```
Yudhees\LaravelVueController\vuecontrollerserviceprovider::class

```

Note
----

[](#note)

The service Provider Contains the Default Route , Be Sure that This Route is not registered in any of your route file

```
Route::post('/vuecontroller',vuecontroller::class)->name('vuecontroller');

```

Usage
-----

[](#usage)

Note

In This Example I am using Inertia.js

In Your `app.js` file simply add this

```
import {controller} from '../../vendor/yudhees/laravel-vue-controller/compostables/global.js'

```

`app.js`

```
//resources/js/app.js
  import './bootstrap'
  import { createApp, h } from 'vue'
  import { createInertiaApp } from '@inertiajs/vue3'
  import {controller} from '../../vendor/yudhees/laravel-vue-controller/compostables/global.js'
    createInertiaApp({
     resolve: name => {
     const pages = import.meta.glob('./Pages/**/*.vue', { eager: true })
      return pages[`./Pages/${name}.vue`]
     },
      setup({ el, App, props, plugin }) {
     const app= createApp({ render: () => h(App, props) });
     app.use(plugin);
     app.mount(el);
   },
  })
```

Global
======

[](#global)

Two Ways to Inject controller function to vue Components

Provide/Inject
--------------

[](#provideinject)

```
//resources/js/app.js
createInertiaApp({
   ..........
   app.provide('controller', controller) // register controller as a provide
})
```

or
--

[](#or-1)

Global Properties
-----------------

[](#global-properties)

```
//resources/js/app.js
    createInertiaApp({
     ..........
     app.config.globalProperties.controller = controller; // register controller as a  global
     })
```

Controller Fucntion
-------------------

[](#controller-fucntion)

Controller Function Accepts Two Arguments The First Argument Represents Path of the Controller `controller(controllerPath,functionname,params={})`

Note

Default prefix path of the Controller is `App\Http\Controller`

Example
-------

[](#example)

I Created a UserController using This Command

```
  php artisan make:controller UserController

```

The Example `UserController` is Look Like this

```
