I've downloaded a base template from this GitHub Repo based on the following dashboard gentella.
I install the inputmask library with the following command:
npm install inputmask --save
But reading and reading, I'm not sure which is the correct step to integrate the same into an HTML page, I read about mix, saas, Compiling Assets (Laravel Mix).
I try with this:
<script type="text/javascript" src="{{ URL::asset('js/inputmaskpath.js') }}"></script>
and this:
#section('scripts')
{{ Html::script(mix('assets/js/inputmask.js')) }}
#endsection
The question finally is, how import inputmask into my HTML page and what it is the correct path?
When you use npm to download packages, they will be downloaded in node_modules folder and they are not (directly) included/loaded into your project.
You use Laravel Mix to handle the assets compilation. So in your scenario you could handle it as the following:
First of all create a javascript file in resources/assets/js called app.js. Add the following code to be able to load the downloaded package
require('inputmask');
Then using Laravel mix you can compile app.js to produce for you one javascript file. Modify webpack.mix.js in your Laravel root folder to the following
mix.js('./resources/assets/js/app.js', 'public/js/app.js');
Now in your view you could load the javascript file as the following
<script src="{!! mix('js/app.js') !!}"></script>
So, in case of another downloaded package, you install it with npm first, then in your resources/assets/js/app.js file you require that package. Then Laravel mix will take care of combining all required packages into one javascript file.
I suggest you read this documentation for more information about Laravel Mix. This tutorial is useful also.
Related
For example, both jquery and jstree are available with npm.
Therefore, in my Laravel project I can add this to the file "webpack.mix.js":
mix.js('resources/js/app.js', 'public/js').extract(['jquery','jstree']);
When running "npm run dev" then indeed both jquery and jstree ends up in the file "public/js/vendor.js" as expected according to the documentation about Vendor Extraction (which uses "extract(['vue'])" in the example)
As far as I understand, this works because both jquery and jstree are located in "node_modules" thanks to being defined in my "package.json" (by defining "jquery": "^3.2" and "jstree": "^3.3.9")
However, how should I use Laravel Mix to put some other javascript file asset into my large generated "vendor.js" file if that other asset is not available with npm but for example I instead retrieved it with composer?
For example the file "jsvalidation.js" from laravel-jsvalidation
I added that dependency into my project with "composer.json" (by using "proengsoft/laravel-jsvalidation": "^3.0") and then ran "composer update".
Then I used "mix.copy" in "webpack.mix.js" since I have found some info about the jsvalidation and laravel-mix:
Quote: "Keep in mind to copy your files using mix, so add in webpack.mix.js file":
mix.copy('vendor/proengsoft/laravel-jsvalidation/public/js/jsvalidation.min.js', 'public/vendor/jsvalidation/js/');
(as you might notice the above linked page is for "Laravel-6-installation" but currently there seems to be no documentation for Laravel 7 which I am using, but anyway, regarding the laravel-mix stuff I am asking about it should not be depending on which version of the jsvalidation library I am using)
So I have added the above "mix.copy" row to my "webpack.mix.js" file but then what should I to get that jsvalidation file into the large "vendor.js" together with jquery and jstree?
I am trying to add google map search capability for my project and i found a very nice react code for this (https://github.com/ubilabs/react-geosuggest) but i couldn't add this to symfony 4 based admin panel.
To understand what is wrong i created a new symfony 4 project and just added one controller and a twig template.
Generally i followed the following tutorials
https://www.thinktocode.com/2018/06/21/symfony-4-and-reactjs/ and
https://symfony.com/doc/current/setup.html
But when i ran the example i got the following result
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Welcome!</title>
</head>
<body>
<div id="root"></div>
<script type="text/javascript" src="/build/app.js"></script>
</body>
</html>
As you can see, it is just the same code with the index.html.twig; there is no change. React didn't change anything instead of i expected.
This tutorial is not the one i just tried.Also I tried, React Getting Started tutorial and other Symfony 4 + React examples but the result was always same.
You can access the source codes from here:
https://github.com/bahadirarslan/Symfony4ReactProblem
UPDATE
I also tried steps described here https://artemzhuravlev.com/blog/symfony-reactjs-using-encore/ but couldn't make it.
The only thing i want to mention, when i try to run npm install i always get EACCES: permission denied error so i am running npm install with sudo and --allow-root attributes like described here https://www.fahidjavid.com/fix-error-eacces-permission-denied-mkdir/
Finally i found the solution with helps Vincent Le Biannic (https://github.com/Lyrkan) at github.
He took my attention to lines below at webpack.config.js
// will require an extra script tag for runtime.
// but, you probably want this, unless you're building a single-page app
.enableSingleRuntimeChunk()
This config make necessary to call runtime.js (which was generated by encore) in html file.
But adding only runtime.js didn't help so i also added vendors-app.js and voila!
Interestingly neither symfony's original documentation nor any tutorial about this subject don't contain any single line about this situation.
If you see an EACCES error when you try to install a package globally, you can either:
Reinstall npm with a node version manager (recommended),
or
Manually change npm’s default directory
Source : https://docs.npmjs.com/resolving-eacces-permissions-errors-when-installing-packages-globally
The same problem for me
I added the line the twig header
<script type="text/javascript" src="{{ asset('build/vendor/app.js') }}"></script>
and it works
I'm new to laravel and I'm using laravel 5.6 but the problem is when I run auth:make command it execute and display some login field and register field. My question is why front end desing is not working after running auth:make command in laravel. I have uploaded image it shows only html content but front-end desing is not showing.
Go to :
app/resources/views/auth/layouts/app.blade.php.
find this (line 20 probably):
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
and replace it with this:
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
it works for me laravel 8.x.
https://laravel.com/docs/5.6/frontend
While Laravel does not dictate which JavaScript or CSS pre-processors you use, it does provide a basic starting point using Bootstrap and Vue that will be helpful for many applications. By default, Laravel uses NPM to install both of these frontend packages.
So if you want to use default "front end design" (bootstrap) that comes default by Laravel, and want to use method that Laravel recommends(npm) than you must follow the documentation above.
Did you install node and npm then run the following commands in your laravel root directory ?
npm install
npm run dev
These commands compile related javascript and scss/css files and build your front end.
Also following are some other documents about this subject :
Installation of Node & npm :
https://www.digitalocean.com/community/tutorials/how-to-install-node-js-on-ubuntu-16-04
https://nodejs.org/en/
https://www.npmjs.com
Laravel Mix And the Front-end :
https://laracasts.com/series/laravel-from-scratch-2017/episodes/14?autoplay=true
I'd like to involve jQuery Smart Wizard in my application.
I have update the composer.json and then run composer update.
Here I get the related files in the vendor folder as techlab\smartwizard.
How could I link the css and js file from the twig template?
I have tried to use below command to generate link to the resources.
php bin\console assets:install --symlink --relative
It seems that the command only deal with the folder in resources\Public in each Bundle.
I hope I could use some link as below to get the files.
<link rel="stylesheet" href="{{ asset('bundles/XXX/static//styles/XXX.css') }}">
I know I could create CSS and JS folder under web folder and then copy the related files there. I just wonder if I have to do this manually then why I use composer to install it. I could just download the file and put them in the target folder. That's all.
I am not sure if there is some better way to manage the resource.
Thank you very much for your help.
assets:install command works only if it finds directories/files in Resources/public directory.
I see two options here:
1) create a bundle and add the files in the Resources public directory
2) use bower and install this package as a dependency for frontend.
For this, you may create a `.bowerrc` file to set the
target directory which can be `web/bower`.
Composer is used to manage php dependencies, not frontend ones, except somebody made a package to work with composer and to be integrated in framework.
So, you can use:
1) composer -> php related, backend dependencies
2) bower, npm -> frontend dependencies
I use a precompiler with gulp that manages css, images and js files in the project
Try
php bin\console
To
php bin/console
Where in your command line
I'm a web newbie programmer,
I'm trying to learn from home to make my own web.
I have notions of php, html, js and css.
But I've found something that is not how to solve.
I'm trying to use Composer to manage Bootstrap. I installed Composer and I have run this line of code
composer require twbs/bootstrap
that has dropped a folder with files.
I do not understand is how I make html links to find the js and css files, you should do indicating the full path?
vendor / twbs / bootstrap / dist / js / bootstrap.js
Excuse me if the question is stupid but I do not know how I should continue.
Amd excuse my English, I'm learning too but by now I use google translate
You could use a post update command in the composer.json file:
"scripts": {
"post-update-cmd": [
"rm -rf public/bootstrap",
"cp -R vendor/twbs/bootstrap/dist public/bootstrap"
]
}
And then just include the javascript- and css-files like this:
<script type="text/javascript" src="{{ ROOT_URL }}bootstrap/js/bootstrap.min.js"></script>
<link href="{{ ROOT_URL }}bootstrap/css/bootstrap.min.css" rel="stylesheet">
Yes, Composer downloads the dependencies by default into the vendor folder. So Bootstrap will also land in the vendor folder, which is not the correct place to reference it or include it.
composer require twbs/bootstrap ➔ vendor/twbs/bootstrap/dist/js/bootstrap.js
Your next step would be to write a little helper script to copy the Boostrap files you need, into your public/assets folder. You could copy the complete dist folder including sub-folders (vendor\twbs\bootstrap\dist) into public or public\assets.
Please overwrite existing files, e.g. if a file exists remove it, then copy it. This allows to easily update the files, when you need to update the Bootstrap vendor package again.
Of course, you could also just copy the files manually or create a symlink. It depends.
That gives you the following directory structure:
public
\- assets
|- css
|- js
\- fonts
\- index.html
When the Boostrap assets are copied you can start to include them, in your index.html or template (assets\js\bootstrap.min.js, etc.).
Referencing: https://stackoverflow.com/a/34423601/1163786 which shows also other solutions to this problem, e.g. fxp/composer-asset-plugin, bower, grunt.
Unless you need customization inside bootstrap (e.g. building scss), the most simple solution is relying on a CDN (as a bonus, you get super-fast caching of assets)
So, simply call your assets like so:
<link href="//netdna.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet">
<script src="//code.jquery.com/jquery-2.2.4.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
Composer is a super-excellent tool for backend dependencies, but not the best one for frontend.
If you want to have the files in your server, and you don't want to use npm, grunt or another frontend library manager, you can simply download the files listed in Massimiliano's answer and put them inside your js/css folders:
First download these files (updated to the most recent Bootstrap 3 version):
http://netdna.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css
http://code.jquery.com/jquery-2.2.4.min.js
http://netdna.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js
And put them in these folders (starting from the root of your project):
public/css/bootstrap.min.css
public/js/jquery-2.2.4.min.js
public/js/bootstrap.min.js
Now, you want to be able to call them in the blade templates for your views. It's simple: just add <link> and <script> tags as normal for any css/js file, adding the following to your blade template:
<link href="{{ url('css/bootstrap.min.css') }}" rel="stylesheet" type="text/css" />
<script src="{{ url('js/jquery-2.2.4.min.js')}}"></script>
<script src="{{ url('js/bootstrap.min.js')}}"></script>
P.s.: if you see the console, it shows something as the following error message:
Source map error: request failed with status 404
Resource URL: http://localhost:8000/css/bootstrap.min.css
Source Map URL: bootstrap.min.css.map
This will not affect the style of your page, and you can simply ignore this message, or remove a line from the bootstrap file as the answers to this question suggest. This answer explain a bit more.