I am currently using Laravel 5.2 framework for my web dev project and stuck on problem. In my dashboard.blade.php i want specify the link to an external css file which is in public/src/css/main.css.
I used URL::to() and URL::asset() methods to get the absolute path to the CSS file but still it is not working.
When i placed my CSS file just inside the public directory everything worked fine but when i place it inside any subdirectory in the public directory it doesnot work.
I am homestead along with the laravel as development environment.
dashboard.blade.php file
directory structure of the project
Please put your css in public folder
<link type="text/css" rel="stylesheet" href="{{ asset('css/style.css')}}">
No matter where you place your css file inside public folder you can get it using the code :
<link rel=stylesheet" href="{{asset('src/css/main.css')}}">
For this code place your css file inside public/src/css
In your image of directory there is no folder as css inside src
Related
I was given a Laravel project and I manage to download it's configuration and get it started on php artisan serve.
When I open it on localhost:8000 It opens but only the html portion of it.
It seems like css files didn't load for it.
Is there some sort of package we need to install with composer in my environment.
To get the css working.
The public folder looks like this in the laravel project.
backend favicon.ico front images index.html index.php js robots.txt sql vendor
web.config
Laravel provides a helper function, asset(), which generates a URL for your assets. You can use this in blade syntax.
Put your css, js files on public folder. for example of a css file, put it on :
../public/bootstrap/css/bootstrap.min.css
In your blade you can access this file from header like this :
<link href="{{ asset('bootstrap/css/bootstrap.min.css') }}" rel="stylesheet" type="text/css" >
hope this help
I have following Codeigniter 4 project structure. I am having problem with using base_url() and setting app.baseURL in .env file properly. Following two questions are due to this same problem:
Project Structure
wamp-web-root
ci_4_project
public
app
assets
APP Structure
public
system
app
Controllers
First_controller.php
Subfolder1
Subfolder2
Subfolder3
Second_controller.php
FIRST QUESTION - controller sub-directories
My First_controller.php
Link" works fine but my Second_controller.php Link" is not working.
SECOND QUESTION - accessing assets folder
I use following code to include css files in my views:
<link href="<?php echo base_url();?>/assets/bootstrap-4.4.1/css/bootstrap.css" rel="stylesheet">
In my .env file: if I use app.baseURL = 'http://localhost/ci_4_project/public/' then Codeigniter Debug Toolbar is displayed but css files are not included in views.
If I use app.baseURL = 'http://localhost/ci_4_project/' i.e. without appending public then css files are included in views but Codeigniter Debug Toolbar is not displayed. Apparently this is because assets folder is not inside public folder but instead at same level so when I use public in baseURL, assets are not included. My question is: how to define app.baseURL and whether to add public or not in the url.
For your second controller, make sure you correctly namespaced it:
namespace App\Controllers\Subfolder1\Subfolder2\Subfolder3;
I am trying to upload a laravel project to cpanel hosting server. My laravel version is 5.3 and php version on the server is 5.6.
What I have done is:
Create a folder called "online_system" to root of file manager.
Copy contents of laravel project except public folder.
Create a folder called "online_system" to public_html.
Copy contents of public folder of laravel project.
Jump to index.php file.
Edit require __DIR__.'/../../online_system/bootstrap/autoload.php';
Edit $app = require_once __DIR__.'/../../online_system/bootstrap/app.php';
Change .env to link DB.
Open domain/online_system.
Home page is working fine, but as long as I click login or register provided by laravel, then the website looks plain without css load.
How can I solve this problem?
Give it a try
<link rel="stylesheet" type="text/css" href="{{ url('online_system/css/styl.css') }}" />
I guess this will do the trick:
<link rel="stylesheet" type="text/css" href="/public/css/style.css"/>
If your project is on the server and change your views, So clear view cache:
php /path_to_your_project/ artisan view:clear
i have installed Laravel 5.4 in localhost. I'm using XAMPP to host the application. I'm using Laravel's inbuilt Blade template structure to show the data. I have used asset() helper to load my assets files which is inside the public folder. A sample code is here.
<link href="{{URL::asset('backend/vendors/bootstrap/dist/css/bootstrap.min.css')}}" rel="stylesheet" type="text/css">
But CSS file is not loading. I discovered this from Chrome developer tool's Network section. I have worked with Laravel before with it's other version and this is the first time that i'm working with version 5.4. Hope someone will assist me to solve this.
you can use only asset function like this i hope you have css folder inside public folder as mentioned in the path.
<link href="{{asset('backend/vendors/bootstrap/dist/css/bootstrap.min.css')}}" rel="stylesheet" type="text/css">
asset()
Generate a URL for an asset using the current scheme of the request (HTTP or HTTPS):
Ref: https://laravel.com/docs/5.4/helpers
I'm using Laravel 5.3 and on some pages the css isn't loading. I tried the suggestions from this question, but they didn't help.
This is what I did so far:
I installed Laravel on wamp inside www/lblog directory so I access laravel's main page via http://localhost:8080/lblog/
To get rid of the "public" part from the URL I moved the index.php and htaccess files from the "public" directory to the root directory and changed two lines in index.php like this:
require DIR.'./bootstrap/autoload.php';
$app = require_once DIR.'./bootstrap/app.php';
In "resources/views/layouts/app.blade.php" I have the styles linked like this:
I tried to remove the / before the "css", it didn't work that way either.
The main page is ok, but if I go to http://localhost:8080/lblog/login for example, the style is broken.
Don't hack the core, use it as it is which is recommended.
Use laravel's built in helpers for generating URL for your assets that are on public directory
<link rel="stylesheet" href="{{ asset('css/styles.css') }}">
which will properly generate URL for your files that are on public directory