I'm building a site using laravel and I want to add a picture in one of the pages. I created an images folder that is located in \app directory and put the picture in the images folder.
So in my blade.php file that loads the site I have this code to load the image
{!! Html::image( asset('app/images/default.png'), 'Profile picture') !!}
However when I load the page I see a broken picture icon and when I inspect the element I get the message
localhost/:24 GET http://localhost:8888/app/images/default.png 404 (Not Found)
I've tried any combination that I could think of in order to make the link work but I always get a 404 error when I load the page.
Any ideas?
You should move your images folder from app to public. Do the same with all css and javascript files.
I think you don't need the app/ in the address. The assets function already know the address of your public folder.
Try it
{!! Html::image( asset('/images/default.png'), 'Profile picture') !!}
Related
say, I have 3 php files inside 'test' folder (eg. example1.php, example2.php, example3.php,) inside cpanel. If a user types test/example1.php, is there any way to only display only test/ inside browser url box using .htaccess file?
The only way to change the URL server-side is with a redirect. The problem there is that once you redirect to test/, how would you know which file to display?
One client-side solution would be to include a JS snippet or file on each page that replaces the current history entry with that of the parent directory. For example
<script>
history.replaceState(null, document.title, './')
</script>
See https://developer.mozilla.org/en-US/docs/Web/API/History_API#The_replaceState()_method
Keep in mind, that if the user does request test/, there's no way to decide which file to render so Apache will just choose the configured directory index. See https://wiki.apache.org/httpd/DirectoryListings
Good morning I write because I have the following problem:
on my home page the js files are loaded correctly but when i enter another page and it is called via "#extends ('admin.layout.admin')" the nav bar will no longer load .js files ... please help me
enter image description here
Did you try
asset
method to load your js file in your code?
put your js file under "public" directory and
try
asset("your js file name")
Or try to use absolutely path
put jquery-3.2.1.min.js file in public/js folder.
link jquery-3.2.1.min.js in head tag.
<script src="{{ asset('js/jquery-3.2.1.min.js') }}" type="text/javascript"></script>
I recently did a fresh install of Lumen framework and started building a site from it. Yes I know lumen is designed only for APIs but please help me out with this.
I have placed all my views inside /resources/views and my templates inside /resources/views/templates.
Now since I had to place [css/js/images] somewhere, I thought placing all of that in public/assets/[css/js/images] would be nice.
Now in my layout when I am trying to include css - I use something like this -
<link href="{{ url('assets/css/something.css') }}">
and it works giving an output of something like this -
<link href="localhost/assets/css/something.css">
same thing works for js also but it gets strange when I try to include images. For including an image I write something like -
<img src ="{{ url('assets/images/someimage.jpg') }}"
and when I view page source, output is as I expect it to be -
<img src="localhost/assets/images/someimage.jpg">
but my console fires 404 not found errors stating someimage.jpg not found. And when I crosscheck by inspecting the image's parent, the Url is totally different soemthing like this -
<img src="localhost/images/someimage.jpg">
See, automatically omitting 'assets' from image url and resulting in 404, but I can see correct url when I view page source.
Things I tried to resolve the issue -
Cleared cache and reloaded the page.
Tried using asset() instead of url() but prototype of that was removed from lumen.
Pull out [css/js/images] folder from assets and pasted them in parent i.e. public. This worked but then the question is why did the previous setup worked find for both css and js and caused problem only with images ?
My other questions are -
1. How can the url in page source be different from the one being rendered ? Just to mention in my case the url in page source worked and displayed image but since the url being renderred omitted 'assets' from path hence resulted in 404.
2. Is there any other good way to include these assets in views. If yes then please also mention where to put them ?
Attaching some images/code for reference.
Output of rendered page showing 404 errors for images but none for css.
Output of view page source windows showing asset included in image path
No clue if this is right, but I believe you actually need to put an image stream inside that URL. Now the server is trying to retrieve some byte encoded object that isn't there.
I have no idea if it's the same case for you, but I've had many instances where I had to put in image streams instead of URLs, which I've solved this way using this library:
Routes.php
/**
* Image handling routes.
* These make sure images actually are images instead of bytecode
*/
Route::get('organization/logo/{logo}', function($logo) {
$file = Image::make(Storage::disk('logo-image')->get($logo));
return $file->response();
});
View
<img src="{{ asset('organization/logo/' . $organization->logo_path) }}" alt="">
I might be completely off, but I recognize what's happening with your app and this took care of the issues when I implemented it.
Check your web server configuration. It sounds like you have some type of redirect setup that redirects assets/images/* to just images/*.
As a simple test, open your "Network" tab and navigate your browser to http://samplelumena.local/assets/images/footer1.jpg. I'm guessing the Network trace will show a 30x (301, 302, etc.) to http://samplelumena.local/images/footer1.jpg, followed by the 404 for that url.
Hi everyone I'm a beginner in Laravel, I have a problem in the page master.blade.php, i.e., that CSS does not apply and when I open the source and I click on the link css it takes me to a HTML page
This is the source code :
This is the link of my css :
Remove all html code tags from your css file (<!DOCTYPE html>, <html>, <head> etc).
See some more information here: http://www.w3schools.com/css/css_howto.asp
try to do it like this
{{ url('css/custom.css'); }}
put ur css in the public folder ( public/css/custom.css ) same is for js
Hey everyone thanks for all, i fix my problem it's just in the folder public adding another folder assets and the style will be in this folder assets in the folder public not resources.
-like this :
public/assets/mystyle.css
I need to generate PDF documents and have them send by email as well as make them reachable by a link.
Sending by email is OK, but I have no idea how to create the link.
Since I use Laravel 4, all links are going through routes.php.
So how do I create a link to a file at a given directory?
Link
will not work, since the route is not known by laravel...
To generate a link to a physical file or directory, that you don't want to run through Laravel's application (e.g. through index.php), use URL::asset().
URL::asset('assets/pdf/file.pdf');
This assumes you've created a physical PDF file on your server that you want to link to. If your PDF file is dynamic and generated/retrieved through your Laravel application, you should use URL::to(), URL::route(), or similar.
Martin Tale is right, but this is another way of accomplishing the same using Laravel's Blade:
{{ link_to('/assets/pdf/file.pdf', 'Link') }}
Create that PDF somewhere in public directory and then create a link to that file like this:
URL::to('path/to/public/directory/file.pdf')
if you are using laravel 4's MAIL feature you can add this to it
$message->attach($pathToFile);
but the .pdf in your public directory under a pdf folder and that will make it:
$message->attach('pdf/mypdffile.pdf');
the same can be for a link which you can add to the email
{{ URL::to('pdf/mypdffile.pdf') }}
You shouldn't need a route to create a link it can be done by blade.
Another way, in a view:
some text
This link will go to public folder.