I have a problem with displaying pictures in View for my project in Laravel..destination path in my application where the photos were saved is: public_path (/ images) but recently I put the project on the server in cpanel, and to get rid of / public from the url, I used a google article, and I made a folder called laravel outside the public_html folder, in which I keep the application files and in public_html I keep only the files that were in the public folder of the application. In View I display the pictures as follows: "{{asset ('images /'. $ Img-> file_name)}}" .. Only it is no longer displayed. Pictures are saved but no longer displayed. I mention that it is saved in the Laravel folder which is outside the public_html folder..and I think that public / images was created automatically there..I would like to know if anyone has faced such a thing and what is the solution. thank you
I solved the problem like this:
In AppServiceProvider in register() I put this code:
$this->app->bind('path.public', function () {
return base_path('../public_html');
});
and now I have public_html/images and there my images are saved..and the rest of myy app, outside public_html folder in a different folder named laravel_project
In Laravel 8, I solved it adding this to the /app/Providers/AppServiceProvider.php in register method:
public function register()
{
$this->app->bind('path.public', function () {
return base_path('../public_html');
});
}
But in order to create the symlink from the "php artisan storage:link" command, I also had to add this code to /bootstrap/app.php, just after the last singleton:
$app->bind('path.public', function () {
return base_path("../public_html");
});
Finally I used this code to get the image that will be sent to my blade template:
$image=Storage::disk('public')->url('path_to_image');
Related
I am trying to write an endpoint which exports the data from the users table i currently have into a CSV file which is downloaded upon clicking of a button. I have setup the controller, routes, export file, and added in the button within the view but everytime i go to click the button it just directs me to the admin/user/export then gives me a 404 but shouldnt it just stay on the same URL then just add the file to my downloads file?
This is the package i am using for Laravel
https://github.com/maatwebsite/Laravel-Excel
web route
Route::get('users/export', 'Admin\UserController#export')->name('users.export');
UserExport
class UsersExport implements FromCollection
{
public function collection()
{
return User::all();
}
}
Controller Function
public function export()
{
return Excel::download(new UsersExport, 'users.csv');
}
Summarise problem:
Everytime i click the button on the view page it directs to admin/users/export then gives me a 404 when i want it to just download the CSV file for the users.
Some help to see where i am wrong would be helpful!
Thanks.
The problem is that two of your routes conflict with each other.
Given the following two routes:
Route::get('users/{user}', 'Admin\UserController#show')->name('users.show');
Route::get('users/export', 'Admin\UserController#export')->name('users.export');
Currently Laravel assumes that when you are trying to access users/export you actually want to access users/{user} with export as the route parameter {user}.
Making sure that users/export is registered before users/{user} should solve your issue:
Route::get('users/export', 'Admin\UserController#export')->name('users.export');
Route::get('users/{user}', 'Admin\UserController#show')->name('users.show');
I deployed a laravel app to shared hosting (hostinger). Everything is working fine except the images which are not showing up.
I have created a symlink of my storage folder with my public_html folder. Files uploaded enters the public folder but when I link the images they still do not show up.
I have created a symlink to the public_html since I cannot access the public folder. I need help on this please
I need the image to be displayed on the browser
In default Laravel deployment the symlink is created in public folder as storage and links to ../storage/app/public.
In order to debug your problem, please have a look at the developer tools of your browser to find out whether it is a 404 or 403 problem (or even another).
Please check for correct permissions. Otherwise you may change the physical storage path to something inside the public folder. This avoids the requirement to create a symlink. Keep in mind to protect non-public storage via .htaccess for example.
You have to the path to your public assets directory if it is not public directory in the root folder. In your case, the public assets directory is public_html. So please bind the path to it from the root folder.
class AppServiceProvider extends ServiceProvider
{
/**
* Register any application services.
*
* #return void
*/
public function register()
{
if (App::environment('prod')) {
$this->app->bind('path.public', function() {
return base_path('../../public_html');
});
}
}
}
had the same problem, remember to run 'php artisan config:cache' as per Laravel Deployment guidelines.
Running the command creates a general configuration file
in app/bootstrap/cache/config.php with all settings including directories and links that you should update
I am trying to build a portal in Laravel to serve some other, standalone web apps (not built in Laravel), but I am struggling to find out how to route to these apps if I want to place them outside the public folder.
In the past, I would use (temporary) symlinks for this kind of things, but I was wondering if Laravel provides another solution.
So, I have a folder:
module
module/index.php
module/js/whatever
module/css/whatever
module/img/whatever
and I want a route /modules/1 to link to index.php in the module-folder in such a way that the resources in this folder (js/css/img) are also accessible.
Any suggestions?
You can include other PHP files with require_once.
web.php
Route::any('/webapp/{assets?}', 'WebAppController#index');
WebAppController
class WebAppController {
public function index(Request $request) {
require_once '../module/index.php';
if ($request->assets) {
// check from session if user is logged in
// require asset as well
// (or download them https://laravel.com/docs/5.5/responses#file-downloads)
}
}
}
http://php.net/manual/en/function.require-once.php
I have a laravel json api being consumed by an angular 4 app,when it comes to deployment,I'm using forge with the contents of the dist folder in laravel's public folder,but I can't refresh any of my angular routes because laravel doesn't recognise them,they only work when navigating normally(clicking and so on) not when I enter them into the address bar of the browser or refreshing as I said.How can I solve this problem?
I have a same problem, so I figured out a way for over 3 hrs.
Here is my way.
1. Build angular 4 project first(ng build)
2. Copy all files except for 'index.html' in dist folder to public directory of laravel project.
3. replace content of resources/views/welcome.blade.php with angular4 index.html
4. add following codes to routes/web.php
Route::get('/{any?}', function () {
return View('welcome');
});
Please let me know if you have a problem still.
Hello I have installed laravel 4 on my server, the installation was done from cpanel , I get the default welcome message of Laravel on this link http://www.mysite/laravel/public
I added a controller and a view and I tried to run the url for that new controller and I get a Error 404 - Not Found
The document you are looking for may have been removed or re-named. Please contact the web site owner for further assistance.
This is what I did after laravel was installed :
TestController.php
<?php
class TestController extends BaseController {
public function index()
{
return View::make('index');
}
}
routes.php
Route::get('/Test', function()
{
return View::make('index');
});
views/index.php
<h1>Test</h1>
am I doing something worng?
here is my folder structure :
I had a similar problem when deployed my project on a host the first time.
You should put all the content of your public folder in the pre-existing public or public_html folder and the whole app folder in the root folder of the server.
Then you change app/config/app.php to tell the new path of app to laravel, and change your .htaccess file to point the document root to the new public folder.
This worked for me, if you need additional details, ask.