So I'm very new to Laravel and I'm following a tutorial to use the authentication feature. This works fine, however it is unable to find my scripts and stylesheets. I haven't made any new ones nor have I touched the stylesheet link in app.blade.php, so I have no clue why it is throwing this error.
Code:
<link href="{{ URL::asset('css/app.css') }}" rel="stylesheet">
Error:
GET http://localhost:8000/css/app.css net::ERR_ABORTED 404 (Not Found)
When I go to locahost/css/app.css I get a 404 error. The same error is occurring with app.js. I haven't changed anything about the file structure and it was all generated with composer create-project laravel/laravel
Thanks.
Laravel doesn't include any CSS files by default. You need to create one yourself and put it to /public/ directory, so in your case that would be /public/css/app.css.
Does localhost point to public in your project? Usually you would have to open http://localhost/public
Per default, URL::asset('css/app.css') expects a css file at /public/css/app.css -- for your setup (serving throught php artisan serve, I suppose?), that would be http://localhost:8000/public/css/app.css.
Anyway: If there is no stylesheet, just create one. There is tons of ways how to do it, depending on your needs. Creating one manually for one, but for complex sites think about using laravel mix for compilation. Or anything other way!
Make sure your style exists at public/css directory, then try this code:
<link rel="stylesheet" href="{{asset('css/app.css')}} type="text/css"/>
if the file doesn't exist, create that and try again.
I hope this can help you.
Related
My laravel project does not find any of the css files of any of the pages. It shows up with the error,
GET http://localhost:8000/dashboard.css net::ERR_ABORTED
Did not find too many of the similar questions but tried the some solutions that I have found but obviously those did not help, otherwise I would not be asking again.
I`m using a Ubuntu PC.
Here are everything that I have tried.
Checked file permissions, all the files have all read, write and execution privileges.
Tried restarting the localhost many times.
Tried using the asset() function, <link rel="stylesheet" type="text/css" href="{{asset('dashboard.css')}}">
Tried using absolute path though I have the css files in the same directory as the blade.php files.
None of the above mentioned ways fixed it. Some clue would help me a lot. Thank you.
The CSS files need to be in the public folder, or a subfolder of public, not the view folder where the blade php files are. public is where you want to put any javascript files, css files, images, or whatever, and the root of the public folder becomes the root of your website when it's running.
I'm trying to set up a SASS to CSS compiler via Mix (previously Elixer) in Laravel 5.4 (using https://laravel.com/docs/5.4/mix). Everything is working fine, it compiles and I can set up a watcher via npm, but referencing it via the views/layout/app.blade.php file, like:
<link rel="stylesheet" href="{{ mix('css/app.css') }}">
doesn't work. In my browser, it is shown of course as:
<link rel="stylesheet" href="/css/app.css">
It is the wrong path. It should be referencing to http://localhost/website/public/css/app.css, but changing anything in the Mix code above, generates a Laravel error.
Unable to locate Mix file: /website/public/css/app.css.
Please check your webpack.mix.js output paths and try again.
What am I doing wrong? Do I need to set a base path somewhere, is my .htaccess wrong, or..? Thank you for any answers.
The path generated by the mix() helper is correct. Your domain should point to directly to "public" directory. Everything above "public" directory should not be accessible via HTTP (it's not safe).
So you need to create new domain (e.g. project.local) and point it to Laravel's public directory (e.g. /home/user/website/public/) or just change default root path in your webserver configuration (DocumentRoot if Apache). Then the URL http://project.local/css/app.css will work.
in webpack.mix.js file configure that file u need like this mix.js('resources/js/app.js', 'public/js') .postCss('resources/css/app.css', 'public/css', []);
after do command npm run watch for mix .
And then u can add your css file anywhere u want like
<link rel="stylesheet" href="{{ asset('css/app.css') }}"/>
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.
I'm having a problem with CakePHP, the CSS is not found. When I view the source code in my browser I can see the cake generic CSS link in the head section. But when I click on it to see the actual source code, I get a 404 not found error.
i follow this actions:
uncommented
Configure::write('App.baseUrl', env('SCRIPT_NAME'));
in app/config/core.php , because rewrite module is disable.
delete .htaccess file from / and /app and /app/webroot.
run project.
php code in default is :
app/View/Layouts/default.ctp
echo $this->Html->css('cake.generic');
and its html code is:
<link rel="stylesheet" type="text/css" href="/app/webroot/css/cake.generic.css" />
this file exist really, but when i click to /app/webroot/css/cake.generic.css in source of browser code i face
404 Not Found
Is way?
I'm assuming your virtual hosts document root points to app/webroot so your links to the css files need to point to /css/file.css. The way you have it now it's actually looking for app/webroot/app/webroot/css and that's why you get a 404.
Either that or your .htaccess is wrong or you stylesheet doesn't actually exist. Let me know if this helps and i can update my answer if needed.
Already,i face this problem. i change permission for app and webroot and css folders. i offer this for you too.
Sorry for opening another topic on this but after hours of researching I haven't found a solution:
As stated in symfony's documentation I want to include my assets (css, js, images) directly and without using Assetic. The documentation is recommending the following sniplet:
<script src="{{ asset('js/script.js') }}" type="text/javascript" />
Unfortunately this always ends in a 404 file not found error for every try. I have placed my assets in the myBundle/Resources/public folder and I also copyied it into the web folder using php app/console assets:install web without success.
What am I missing here? Is there a configuration missing? Thank you in advance.
asset('js/script.js') will produce a link like /js/script.js. The files will be copied to a bundles folder, not to the web root. You want something like this to generate the correct URL:
<script src="{{ asset('bundles/myBundle/js/script.js') }}" type="text/javascript"></script>
(Note also that script tags need to have a closing </script> to make them work cross-browser.)