How do I make Example.vue update in Laravel? - laravel

I just read the answers to this question and wasn't able to get a good response.
Laravel Example.vue not updating
I also posted this question trying to figure it out on my own but to no avail.
how do I load a Vue component in Laravel 5.4?
As another attempt, I just did a new reinstall of Laravel, and while I am able to get the default Example.vue component to load multiple times in a single view, I am still unable to change the contents of the component. Funnier thing is that when I run npm install and then npm run dev, the component ceases to even show up anymore.
This is really frustrating because Laravel ships with Vue.js yet I am unable to utilize it. Any help would be much appreciated! :)

You need to install the node dependencies and then compile them.
Install node.js
From your projects root run npm install
From your projects root run npm run dev
Your browser may also be showing the cached version. Chrome has a setting that you can have the cache disabled while the inspector is open.
You can also check it by opening your project in other browsers.
If when running npm run dev dies without any message of any kind you can delete your node_modules folder then run npm install and then compile your assets again.
You may also need to clear and rebuild a few other caches with commands:
composer dump-autoload
php artisan clear-compiled
php artisan cache:clear
https://laravel.com/docs/5.4/mix
https://laravel.com/docs/5.4/frontend

Double check and make sure you're in the resources directory and not public. If you're in the correct directory try npm install then npm run watch

Related

Suddenly getting "Target class [Inertia\Ssr\Gateway] does not exist." I don't use Inertia's SSR. How can I get back to a functioning site?

I've got a Laravel Jetstream project using Inertia. I've been running it for a while. Launched on Jetstream v1, later upgraded to v2. Everything has been running great. Today I was messing with some composer and npm stuff and suddenly every page is broken. I just get an error that looks like this:
Illuminate\Contracts\Container\BindingResolutionException
Target class [Inertia\Ssr\Gateway] does not exist.
This happens on every view. I have never used Inertia's SSR, and I don't want to (at least not currently). I tried resetting both my composer json files and my npm json files but I cannot get back to my functioning site. I'm losing my mind. Any ideas of how I can get back to my original functioning site?
Try to remove vendor folder and node_modules.
Then run
composer install
and :
npm install
After that try to run these commands:
php artisan cache:clear
php artisan view:clear
php artisan route:clear
composer dump-autoload

Vuejs installed or not?

I am a beginner in Vuejs.I want to develop an application with laravel and Vuejs.I have follow the step of installing laravel and Vuejs and execute this composer create-project --prefer-dist laravel/laravel demo "5.8.*" command.I verify to check that Vuejs is installed or not by adding the extension of Vuejs in google chrome and it showing Vuejs is installed.But when i execute the command vue --version in the putty by connecting server through SSH then it shows error that "vue command not found".Why?
May be this question is not proper to ask but i am very confusing that actually Vuejs is installed or not.And is the Vuejs files structure is same or different?
Thanks in advance.
Installing and compiling vue into a laravel project is different than using the vue cli.
In Laravel, Vue is included in the assets registry in the package.json file.
npm uses this file to pull in assets then allows you to build them. It pulls them in with npm install
Note: you need node.js installed on your system.
The build commands you can see at the top of the package.json. They usually are:
npm run dev, npm run prod, and npm run watch.
Here is the documentation on getting started with Laravel and Vue:
https://laravel.com/docs/7.x/frontend

Error on Laravel after installing VueJS. Request failed with status 404

I am developing a small system with Laravel Framework 5.6.39 and everything was going well, until I installed Vue Js. When viewing in the browser, what should be displayed does not appear and the following appears in the console:
How can I solve this error?
I think you need to run:
npm run watch
After adding VueJS to your project you need to install all dependencies by executing:
npm install
Then you can either compile your assets onetime by executing:
npm run dev
Or start a watcher which compiles your assets automatically after detecting a filechange:
npm run watch
The compile process will generate the app.js file which is missing in your case. You can read more about this process or possibilities in laravel here (laravel docs about frontend).
After pulling your project you need to install all dependencies using
npm i
Then you can build it for development one-time using
npm run dev
Or for real-time updates
npm run watch
And when your project is ready for production
npm run prod

Laravel project auto refresh after changes

Does anyone know if there is a way to run the code changes in a Laravel project without refreshing the page every time.
I know that to see the changes I need to
php artisan serve
but I do it every time and it is kind of frustrating.
Thank you anyways.
You can achieve this with Laravel Mix.
According to this part of the documentation, you need to edit your webpack.mix.js file, and add this to the end:
mix.browserSync('127.0.0.1:8000');
It needs to match to the output of the php artisan serve command, where you found a line something like this:
Laravel development server started: <http://127.0.0.1:8000>
After this, you have to run the php artisan serve, and the npm run watch command simultaneously. You must leave to run both commands while you edit your files.
Note: The first time you run the npm run watch, it installs additional components. But the command output is quite clear on that. If everything is in order, Laravel Mix automatically opens your browser with http://localhost:3000, or something like this.
add in webpack.mix.js file in laravel
mix.browserSync('127.0.0.1:8000');
then run this command
> npm install browser-sync browser-sync-webpack-plugin#2.0.1 --save-dev --production=false
after this run npm run watch
> Browsersync automatic run your port 3000
First make sure you install nodejs, After that install laravel-mix
npm install --save-dev laravel-mix
create webpack.mix.js file in root folder for your project and add to it
const mix =require('laravel-mix')
mix.browserSync('127.0.0.1:8000');
Open package.json file and add to script section:
"scripts": {
"watch": "mix watch"
}
Run laravel project
php artisan serve
To update laravel project auto when you make changes run in another terminal:
npm run watch
Updated from Laravel 9.x
you can use vite instead of laravel-mix, you should run this command to install vite:
npm install
Without any configuration, The next line of code will include auto in master page, If you want to include in another master page like admin, you can write it to auto refresh when make changes:
#vite(['resources/sass/app.scss', 'resources/js/app.js'])
After installing vite, run this command
npm run dev
And run
php artisan serve
For more information, view docs
To achieve this you can use Laravel Mix
Ensure that Node.js and NPM are installed:
run node -v and npm -v.
Install Laravel Mix
npm install.
Install browser-sync and browser-sync-webpack-plugin
npm install browser-sync browser-sync-webpack-plugin --save-dev --production=false
Open webpack.mix.js and add this line
mix.browserSync('127.0.0.1:8000');.
Run Project with these two commands: The npm run watch command will continue running in your terminal and watch all relevant CSS and JavaScript files for changes. Webpack will automatically recompile your assets when it detects a change
php artisan serve. and then npm run watch.

reload all packages using composer

Is it possible to reload all the packages installed using composer? I'm not sure if I made an accidental change to the source of on of the packages, and my app stopped working so I want to rule this out by reloading all the packages.
You can generally just wipe the vendor/ directory and then run composer install to get everything back from your last known state (stored in composer.lock). Some plugins/custom installers in some frameworks however drop packages outside the vendor dir, but as far as I know with Laravel you should be ok doing this.
I think php artisan dump-autoload should help.

Resources