Laravel 5: adding custom styles/scripts - php

This is kind of a stupid question, and I've looked around for similar answers and found some, however they are a bit more specific than what I am asking.
Say I want to include a custom styles.css or scripts.js file, would I just create a css/js folder in resources/views folder, and then call to them in my blade.php files like I would normally do in an HTML file when not using Laravel?
Example: <link type="text/css" rel="stylesheet" href="css/styles.css">
Or is there a different approach to this in Laravel?

Put your css files into the public folder like public/css/styles.css
Use the asset() function to add css, javascript or images into your blade template.
For Style Sheets
<link href="{{ asset('css/styles.css') }}" rel="stylesheet" type="text/css" >
or
<link href="{{ URL::asset('css/styles.css') }}" rel="stylesheet" type="text/css" >
For Javascript
<script type="text/javascript" src="{{ asset('js/scripts.js') }}"></script>
or
<script type="text/javascript" src="{{ URL::asset('js/scripts.js') }}"></script>
You may also be interested to have a look at Laravel's Elixir to process your styles and javascript.

put your style.css file in inside css folder named: /css AND your js file inside js folder named: /jsput below code in your html file.
Your css files
<link rel="stylesheet" href="{{ URL::asset('css/yourstylesheet.css') }}" />
And js files
<script type="text/javascript" src="{{ URL::asset('js/jquery.min.js') }}"></script>

Related

Laravel 8 is not loading css and js

I have css under App/resources/css by default
when I open Login and Register page css is not loading. This is default css and js link on my app.blade.php
<script src="{{ asset('js/app.js') }}" defer></script>
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
I did this
<link href="{{ URL::asset('assets/css/a.css') }}" rel="stylesheet">
and also tried
<script src="{{ asset('resources/js/app.js') }}" defer></script>
<link href="{{ asset('resources/css/app.css') }}" rel="stylesheet">
What shall I do to make it work.??
Move all your CSS and JavaScript to the public folder so that your structure becomes something like
public/
|--- css/
|---js/
Now to use your CSS and JavaScript from your new location do something like
<script src="{{ asset('js/app.js') }}" defer></script>
<link href="{{ asset('css/app.css') }}" rel="stylesheet">
This works because the asset() blade helper already looks from the public directory so you start your CSS and JavaScript URL construction from that point on
I would recommend to always use the mix helper in Blade like this
<script src="{{ mix('/js/app.js') }}"></script>
as it additionally properly takes care of versioned assets. Please make sure you either ran npm run dev or npm run prod (see Compiling assets) to generate the public/css/app.css and public/js/app.js files from the ones located in resources.

Laravel & PHP - Output is not the same in Laravel but working on PHP

Im working on a barcode or qrcode generator and I have a problem, when I integrate my code and asset folders in PHP everything works perfectly fine I can generate the code ! , but when I integrate this to Laravel and put all the links it went down tho it is the similar UI but the output of the program is not working well it is not generating the code.
My folders are placed in public in laravel and main folder only in php
I am currently confused of this problem - when I delete all assets, codes of JS files in PHP, why is it STILL working tho I deleted all the folders like fonts , css and js however in Laravel when I delete the currently said folders, it brings CHANGES tho in PHP everything works and run even tho the codes are deleted and folders are delete. any solution for this?? im wondering is there a setting for this?
P.S I didnt change any single code of them and still confused why it is not working properly in laravel
Is there any possibility to solve this problem?
my links in laravel
CSS & BOOTSTRAP
link href="{{ asset('css/bootstrap.min.css') }}" rel="stylesheet">
<link href="{{ asset('css/style.css') }}" rel="stylesheet">
JS
<script type="text/javascript" src="{{ asset('/js/filereader.js') }}"></script>
<script type="text/javascript" src="{{ asset('js/qrcodelib.js') }}"></script>
<script type="text/javascript" src="{{ asset('js/webcodecamjs.js') }}"></script>
<script type="text/javascript">
links in PHP
CSS
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/style.css" rel="stylesheet">
JS
<script type="text/javascript" src="js/filereader.js"></script>
<script type="text/javascript" src="js/qrcodelib.js"></script>
<script type="text/javascript" src="js/webcodecamjs.js"></script>
change your CSS/JS Directory Structure in Public folder.
CSS:
<link href="{{ asset('filepath') }}" rel="stylesheet" type="text/css" >
JS:
<script type="text/javascript" src="{{ URL::asset('filepath') }}"></script>
For CSS:
<link href="{{ asset('css/bootstrap.min.css') }}" rel="stylesheet" type="text/css" >
<link href="{{ asset('css/style.css') }}" rel="stylesheet" type="text/css" >
Make your directory structure is like this for CSS: /public/css/bootstrap.min.css and /public/css/style.css
For Javascript:
<script type="text/javascript" src="{{ URL::asset('js/filereader.js') }}"></script>
<script type="text/javascript" src="{{ URL::asset('js/qrcodelib.js') }}"></script>
<script type="text/javascript" src="{{ URL::asset('js/webcodecamjs.js') }}"></script>
Make your directory structure is like this for JS: /public/js/filereader.js and /public/js/qrcodelib.js and /public/js/webcodecamjs.js

How to include External CSS and JS file in Laravel 5.5

I am Using Laravel 5.5, the Form and HTML Helper are removed from this version. I don't know how to include external style sheet and JavaScript files in my header file.
Currently I am using this code:
{{ HTML::style('css/bootstrap.min.css') }}
put your css in public/css and js in public/js and add follow code *.blade.php file
e.g.
<link href="{{ asset('css/app.min.css') }}" media="all" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="{{ asset('js/app.min.js') }}"></script>

Can't load CSS in Laravel

Hi I am currently learning Laravel and seem to be having issues loading custom CSS that is located in the public/css/bootstrap.css.
I have been attempting to load it via
<link href="{{ asset('css/bootstrap.css') }}" rel="stylesheet" type="text/css" >
But it is if the CSS is not getting picked up. When I view the page source (http://portfollo.co.uk/css/bootstrap.css) I just get an error. Any ideas ?
Try with public/css/bootstrap.css
<link href="{{ asset('public/css/bootstrap.css') }}" rel="stylesheet" type="text/css" >
OR
<link href="'/css/bootstrap.css'" rel="stylesheet" type="text/css" >
You should put your css file inside public folder, (app/public):
then in your head:
<link rel="stylesheet" href="{{ url('/') }}/style.css" type="text/css"/>
Public folder will contain all css and js files, you can also create assets folder inside public folder and then point to correct path:
<link rel="stylesheet" href="{{ url('/') }}/assets/css/style.css" type="text/css"/>
change name as public/css/bootstrap.css and put css in that folder. and give the same path.
This is not a CSS error. its Routing error. check your route.php file just check your source code like this view-source:http://portfollo.co.uk/css/bootstrap.css
you are trying something wrong ??

laravel routing css and js scripts

I have a laravel project and just wanted to use a simple timer jquery script in it. I created a new folder in views, placed there my code. I also placed there another folder called flip_timer with jquery files.
My problem is that i cannot make the script paths work "not found http exception".
Folder structure looks like this: folder in views > contains file(code below) and folder including all the needed files. Whenever i try to run the link with code the page is empty, and when i click to see the source code and click on the css or js link it shows me the error i mentioned above...
<link rel="stylesheet" type="text/css" href="flip_timer/jquery.flipcountdown.css" />
<script type="text/javascript" src="flip_timer/jquery.min.js"></script>
<script type="text/javascript" src="flip_timer/jquery.flipcountdown.js"></script>
<div id="retroclockbox1">
<script>
jQuery(function($){
$('#retroclockbox1').flipcountdown();
})
</script>
</div>
put your jquery.flipcountdown.css file in inside css folder named: css/flip_timer/jquery.flipcountdown.css
AND
your both js file inside js folder named:js/flip_timer/jquery.min.js and js/flip_timer/jquery.flipcountdown.js and then put below code in your html file.
<link rel="stylesheet" href="{{ URL::asset('css/flip_timer/jquery.flipcountdown.css') }}" />
AND for js file
<script type="text/javascript" src="{{ URL::asset('js/flip_timer/jquery.min.js') }}"></script>
<script type="text/javascript" src="{{ URL::asset('js/flip_timer/jquery.flipcountdown.js') }}"></script>

Categories