I have my Laravel project that is hosted on a server, I made a copy of that project for testing and development on my local pc, but there is a difference that I don't know how to solve. On my local pc I do not need to specify public folder to access css files and other stuff, but on my server I have to specify, otherwise I doesn't find those files in public folder.
Example code on server:
<link rel="stylesheet" href="/public/css/main.css">
And on my local pc
<link rel="stylesheet" href="/css/main.css">
So I would love to make this thing the same on my local project, because now everytime I push changes to the server I need to add public to all the stuff and that's annoying. If I understand correctly it is done for security purposes, but I don't know how to make it on my project.
Use Laravel asset() function like below,
<link rel="stylesheet" href="{{asset('css/main.css')}}">
Related
I am developing a small web app using Laravel 5.6.
I recently upgraded Laravel to 5.6 and therefore also updated PHP to version 7.2.3 as php7.1 is a requirement for Laravel.
I am developing on a Windows 10 machine.
For testing I am using the php built-in webserver.
I either use the Laravel shortcut to start the server php artisan serve or I call directly the php -S localhost:8000 -t public command, the result is the same.
Since I updated php, I am not able to access any asset (css, js) through the browser.
blade file:
<head>
<meta charset="UTF-8">
<title>My Site</title>
<link href="{{ asset('css/search.css') }}" rel='stylesheet'>
</head>
Output in Chrome:
<head>
<meta charset="UTF-8">
<title>My Site</title>
<link href="http://localhost:8000/css/search.css" rel='stylesheet'>
</head>
Folder structure of the laravel project is:
- Root of Laravel Project
- public
- css
- search.css
I can't access the search.css file by entering http://localhost:8000/css/search.css, the server logs 127.0.0.1:52980 [404]: /css/search.css - No such file or directory
The file is in the right place, and the generated urls are also correct. In fact I didn't change anything and with older php version it worked. But of coursed I double checked a dozent times.
Validating the path in my controller.php with a few lines of code:
public function index(Request $request)
{
$t3 = public_path("css\\search.css");
var_dump($t3);
var_dump(file_exists($t3));
}
And the result was:
string(91) "C:\Users\me\Documents\LaravelProject\public\css\search.css" bool(true)
Deploying the application to a AWS EB environment will work.
So my guess, that there is a problem with the built-in webserver.
Can anybody imagine, what is wrong?
The small webserver is of course very handy during development.
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 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
{I asked for this question before but didn't get a solution, so please try and understand..}
I am able to run my external javascript and css on my local machine, but I am unable to fetch the same on my shared hosting with go daddy (cannot afford dedicated)!
Although I could use the style and js if written internally...
I have tried a bunch of methods like:
<link href="{{asset('css/clock.css')}}" rel="stylesheet" media="all" />
OR:
<link href="{{URL::asset('css/clock.css')}}" rel="stylesheet" media="all" />
OR:
{{HTML::style('css/clock.css')}}
OR this one:
<link href="{{ url('css/clock.css')}}" rel="stylesheet" media="all" />
I installed laravel using this tutorial, which included in making of one more .htaccess file in www folder.
so how do i tackle this? please help!
Your #include statements in your CSS files that reference external stylesheets are what's throwing the error.
Simply don't use #import statements without https:// URL's. If you have to, then use something like a gulp task to fetch those and compile for you on the server side (although I still don't like this, and think it better to use package management like npm or bower).
If your domain is SSL protected your css and js has to be a "https".
To do so for external links(CDN links) make sure you are giving it like "https://link.com/test.css"..
And to add internal links from public folder
user
{{ asset('css/clock.css', true) }}
Here in asset true parameter adds https instead of http