I can´t link Bootstrap 4.1.0 to my Laravel project - php

I´m trying to link bootstrap css to my Laravel proyect using
or in my view but it not working.
In scss class I tried this:
#import 'node_modules/bootstrap/scss/bootstrap' or #import '~bootstrap/scss/bootstrap';
In view class I tried this:
<!--<link rel="stylesheet" type="text/css" href="css/app.css"/>-->
or <link rel="stylesheet" type="text/css" href="{{url('css/app.css')}}"/>
My scss class looks like this:
#import url('https://fonts.googleapis.com/css?family=Nunito');
#import 'variables';
#import '~bootstrap/scss/bootstrap';
//#import 'node_modules/bootstrap/scss/bootstrap';
#import 'custom';
They show any errors, but it don´t load the bootstrap styles

First of all, you'll to go to your prompt and type
npm install bootstrap#4.1.0
Then, in your bootstrap.js file, inside the try statement, type this:
require ('bootstrap');
In your app.scss file
#import '~bootstrap/scss/bootstrap';
Run:
npm run dev
In your view
<link rel="stylesheet" href="{{ asset('css/app.css') }}">
<script src="{{ asset('js/app.js') }}"></script>

looking at your description, you only need to run npm dev
npm run dev
and add in any .blade.php file
in head tag:
<link rel="stylesheet" href="{{ asset('css/app.css') }}">
in body tag:
<script src="{{ asset('js/app.js') }}"></script>

Related

I cannot find bootstrap.css in my folders

I can't find the path for my CSS documents.
My bootstrap.css is located at https://i.hizliresim.com/P7kRGO.jpg and here is the error message I get: https://i.hizliresim.com/7BgOQN.jpg
<link href="https://fonts.googleapis.com/css?family=Encode+Sans+Expanded:400,600,700" rel="stylesheet">
<!-- Stylesheets -->
<link href=./plugin-frameworks\bootstrap.css" rel="stylesheet">
<link href="../views/plugin-frameworks/bootstrap.css"rel="stylesheet">
<link href="./fonts/ionicons.css" rel="stylesheet">
<link href="/common/styles.css" rel="stylesheet">
I'm using PHP 7, Laravel 5.4, and running on xampp Apache.
Use asset helper like this to link a resource in public directory:
<link rel="stylesheet" href="{{asset('styles/main.css')}}">

Pushing Laravel 5.2 app to Heroku, all files in public/ are missing

I have a Laravel application deployed on Heroku. However, all files that are in 'public' folder of my application are not loaded.
That is, no css and / or js are loaded pages after deployment. Only HTML is loaded.
This is the structure of my 'public' folder:
I'm loading the css that way:
<link href="{{ URL::asset('css/bootstrap.min.css') }}" rel="stylesheet">
And JS that way:
{!! Html::script('js/parsley.min.js') !!}
EDIT
I've figured out what was wrong.
Instead of loading the css the way I was doing, I should do this:
<link href="{{ asset('css/parsley.css') }}" rel="stylesheet">
And for Js:
<script type="text/javascript" src="{{ asset('js/parsley.min.js') }}></script>
It's very strange.
Are you sure that the files exist in the public folder?
Laravel 5.2 does not include html helpers function out the box, do you update your composer?
You can remove helper function and try without it, just use...
for css
<link href="/css/bootstrap.min.css" rel="stylesheet">
and js
<script src="/js/parsley.min.js"></script>
if everything is ok, the problem is in your helper functions.

Symfony the right way assets path

I am trying to find out, how to get path of my css and js files.
This is my base.html.twig in app/Resources/views/base.html.twig
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>{% block title %}Welcome!{% endblock %}</title>
<link rel="icon" type="image/x-icon" href="{{ asset('favicon.ico') }}" />
<link rel="stylesheet" type="text/css" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/bootstrap-theme.min.css">
</head>
<body>
{% block body %}{% endblock %}
<script src="js/jquery-2.1.4.min.js"></script>
<script src="js/bootstrap.min.js"></script>
</body>
</html>
It cant find my assets, because it is seeking in web/ directory by default. How should my path look like to find the files in app/Resources/views?
thanks!
Try to include stylesheet as below :
{% stylesheets 'css/bootstrap.min.css'
'css/bootstrap-theme.min.css'
filter='cssrewrite' %}
{% enstylesheets %}
Also you should install assets and you can use symlink option to assets:install command. This will make symlink in web folder to your bundle public folders
app/console assets:install --symlink
Without symlink option this task makes copy of files, so your changes doesn't affect.
You should also use assetic:dump command
app/console assetic:dump
Clear the cache as well.

How to include External CSS and JS file in Laravel 5

I am Using Laravel 5.0 , the Form and Html Helper are removed from this version , i dont know how to include external css and js files in my header file. Currently i am using this code.
<link rel="stylesheet" href="/css/bootstrap.min.css"> <!--- css file --->
<script type="text/javascript" src="/js/jquery.min.js"></script>
I think that the right way is this one:
<script type="text/javascript" src="{{ URL::asset('js/jquery.js') }}"></script>
Here I have a js directory in the laravel's app/public folder. There I have a jquery.js file. The function URL::asset() produces the necessary url for you. Same for the css:
<link rel="stylesheet" href="{{ URL::asset('css/somestylesheet.css') }}" />
Keep in mind that the old mehods:
{{ Form::script() }}
and
{{ Form::style() }}
are deprecated and will not work in Laravel 5!
Try it.
You can just pass the path to the style sheet .
{!! HTML::style('css/style.css') !!}
You can just pass the path to the javascript.
{!! HTML::script('js/script.js') !!}
Add the following lines in the require section of composer.json file and run composer update "illuminate/html": "5.*".
Register the service provider in config/app.php by adding the following value into the providers array:
'Illuminate\Html\HtmlServiceProvider'
Register facades by adding these two lines in the aliases array:
'Form'=> 'Illuminate\Html\FormFacade',
'HTML'=> 'Illuminate\Html\HtmlFacade'
In laravel 5.1,
<link rel="stylesheet" href="{{URL::asset('assets/css/bootstrap.min.css')}}">
<script type="text/javascript" src="{{URL::asset('assets/js/jquery.min.js')}}"></script>
Where assets folder location is inside public folder
i use this way, don't forget to put your css file on public folder.
for example i put my bootstrap css on
"root/public/bootstrap/css/bootstrap.min.css"
to access from header:
<link href="{{ asset('bootstrap/css/bootstrap.min.css') }}" rel="stylesheet" type="text/css" >
hope this help
Place your assets in public directory and use the following
URL::to()
example
<link rel="stylesheet" type="text/css" href="{{ URL::to('css/style.css') }}">
<script type="text/javascript" src="{{ URL::to('js/jquery.min.js') }}"></script>
At first, you have to put your .css or .js files in the public folder of your project. You may create subfolders to it and move the files into the subfolder. Then you have to do the followings
<link rel="stylesheet" href="{{asset('css/your_css_file.css')}}">
<script src="{{asset('js/your_js_file.js')}}"></script>
In my example, I have created two subfolders called css and js. I put all of the .css and .js files in corresponding folders and use them where ever I want them. Thank you and hope this helps you.
There are many ways to include external css and js files as specified in below code but you can choose one of them, i have tested them all, they work the same.
<link rel="stylesheet" href="{{ asset('css/stylesheet.css') }}" /><!--Recommended-->
<link rel="stylesheet" href="{{ URL::asset('css/somestylesheet.css') }}" />
<link rel="stylesheet" href="{{ URL::to('css/otherstylesheet.css') }}" />
<link rel="stylesheet" href="{{ url('css/anotherstylesheet.css') }}" />
Maybe there are more ways to load it.
but keep in mind that if you are loading the css and js from other than a public folder then better to use Laravel mix.
{{ HTML::style('yourcss.css') }}
{{ HTML::script('yourjs.js') }}
Laravel 5.5 comes with mix , the replacement for Elixir, the external css(sass) can be extracted to resources/assets/css(sass) and import to app.css(scss) or give the correct path to your node_module folder that contains the library and can be used as
<link rel="stylesheet" href="{{ mix('css/app.css') }}" >
The same can be done for Javascript too .
Ok so I was able to figure out for the version 5.2. You will first need to create assets folder in your public folder then put css folder and all css files into it then link it like this :
<link href="assets/css/bootstrap.min.css" rel="stylesheet">
Hope that helps!
CORRECT & SECURED WAY
If you have a external .css or .js file to add into your page!
My version : Laravel Framework 5.7
If you want to add a External .js file..
Copy your External codes.
Run command npm install in your terminal.
When the above command is executed you can see a folder named node_modules.
Then go to resources/js.
Open file app.js.
Scroll down to the bottom and paste your External JS.
Finally run command npm run dev in your terminal.
your scripts will be updated and its compiled and moved to public/js/app.js . by adding a .js file in public folder will not effect on your page.
If you want to add a External .css file..
Copy your External styles.
Run command npm install in your terminal.
When the above command is executed you can see a folder named node_modules.
Then go to resources/sass.
Open file app.scss.
Scroll down to the bottom and paste your External Styles.
Finally run command npm run dev in your terminal.
your scripts will be updated and its compiled and moved to public/css/app.css . by adding a .css file in public folder will not effect on your page.
Easiest and the safest way to add your external .css and .js.
Laravel JavaScript & CSS Scaffolding
YouTube Compiling Assets
First you have to install the Illuminate Html helper class:
composer require "illuminate/html":"5.0.*"
Next you need to open /config/app.php and update as follows:
'providers' => [
...
Illuminate\Html\HtmlServiceProvider::class,
],
'aliases' => [
...
'Form' => Illuminate\Html\FormFacade::class,
'HTML' => Illuminate\Html\HtmlFacade::class,
],
To confirm it’s working use the following command:
php artisan tinker
> Form::text('foo')
"<input name=\"foo\" type=\"text\">"
To include external css in you files, use the following syntax:
{!! HTML::style('foo/bar.css') !!}
I may be late to the party but it's easy to include JS and CSS the Laravel Way by simply using asset() function
e.g.
<link rel="stylesheet" href="{{ asset('css/app.css') }}" />
Hope that helps
I have been making use of
<script type="text/javascript" src="{{ URL::asset('js/jquery.js') }}"></script>
for javascript and
<link rel="stylesheet" href="{{ URL::asset('css/main.css') }}">
for css, this points to the public directory, so you need to keep your css and js files there.
It mostly happens due to laravel webpackmix is not yet executed
composer require laravel/ui
PHP artisan ui vue --auth //you can use vue boostrap --auth is to add the login paths and
npm install
if it's asking to run "npm fund" then do it
npm run dev
try this once again

codesleeve asset pipeline not compiling or concatenating except on local

I am using Codesleeve Asset Pipeline in Laravel 4 to serve my css and js files.
Unfortunately it does not want to compile bootstrap in a staging environment.
This is the config:
'paths' => array(
'app/assets/javascripts',
'app/assets/stylesheets',
'app/assets/images',
'lib/assets/javascripts',
'lib/assets/stylesheets',
'lib/assets/images',
'provider/assets/javascripts',
'provider/assets/stylesheets',
'provider/assets/images',
'vendor/twitter/bootstrap/less/',
'vendor/twitter/bootstrap/js/',
),
Those 3 lines are the only ones changed.
On my local instance it works fine, I get one css file including all of bootstrap and my own stuff, and one js file with jquery and the bootstrap plugins I asked for.
But on the staging server, I get this:
<link href="http://website.net/assets/vendor/twitter/bootstrap/less/bootstrap.less" rel="stylesheet" type="text/css">
<link href="http://website.net/assets/application.css" rel="stylesheet" type="text/css">
<script src="http://website.net/assets/jquery.min.js" ></script>
<script src="http://website.net/assets/vendor/twitter/bootstrap/js/button.js" ></script>
<script src="http://website.net/assets/vendor/twitter/bootstrap/js/dropdown.js" ></script>
<script src="http://website.net/assets/application.js" ></script>
I think that the asset pipeline is not even trying to concatenate or compile anything.
It turned out that the minifier was barfing on bootstrap 3's css, and not producing the file. However no error was thrown.
You need to add your staging server on the config asset-pipeline so it also compiles on this stage.

Categories