i am trying to download a file in laravel. It works fine in localhost but not in production. The file path is ok. but the problem is when i am trying to download it. It gives an error saying the file doesnt exist. Below is my code. please help. thanks in advance
public function getGo(Request $request){
$file=asset('storage/source/hey.png');
return response()->file($file);
}
Can you try the below code?. I think below code would be helpful.
public function getGo(Request $request){
$file=storage_path('source/hey.png');
return response()->file($file);
}
Related
I am totally new to laravel, I have been creating a project to pay with transbank, everything is fine, but when I return my url I can't find my localhost path.
Laravel's artisan server starts withphp artisan serve --host=my-ip-address --port:8000 I really don't know what happens.
Do I occupy windows, do I have to install any configuration? or while this environment should be done on a server like Xampp and do some configuration? I am super lost, my return url in laravel I leave it like this in the browser.
http://my-ip-address:8000/initPay
So it starts, it goes to the transbank page and everything is fine, but when returning the url that I specify in the method it does not work.
my code laravel
web routes
Route::get('/initPay', 'WebPayPlussController#initPayWeb');
Route::post('/confirm_pay', 'WebPayPlussController#confirmPay');
Controller
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Transbank\Webpay\WebpayPlus;
use Transbank\Webpay\WebpayPlus\Transaction;
class WebPayPlussController extends Controller
{
public function __construct(){
WebpayPlus::configureForIntegration('597055555532', '579B532A7440BB0C9079DED94D31EA1615BACEB56610332264630D42D0A36B1C');
}
public function initPayWeb(Request $request){
$buy_order ='abc456';
$session_id='4784568';
$amount=10000;
$response = (new Transaction)->create(
$buy_order,
$session_id,
$amount,
'http://my-ip-address:8000/confirm_pay');
$url =$response->getUrl().'?token_ws='.$response->getToken();
return redirect()->away($url);
}
public function confirmPay(Request $request){
$confirm= (new Transaction)->commit($request->get('token_ws'));
if($confirmacion->isApproved()){
return 'is Approved';
}else{
return 'is not Approved';
}
}
}
Please, if someone can guide me more on the subject or how to make it return to the localhost url, I would really appreciate it, I searched and I am still lost..
Route /confirm_pay will definitely not work with a private IP address... which isn't route-able.
You would need to deploy that script to a server with a publicly available IP address.
ngrok might be a possible workaround, but a rather cumbersome one.
Can you please help me this error,i am stuck in that error from two days. i have work in laravel multiple images upload.but whenever i upload the images it will show below error msg..
Spatie\MediaLibrary\Exceptions\FileCannotBeAdded\FileDoesNotExist File D:\xampp\htdocs\abc\storage\prop_images/5f211fbd7fa1a_p1.jpg does
not exist
namespace Spatie\MediaLibrary\Exceptions\FileCannotBeAdded;
use Spatie\MediaLibrary\Exceptions\FileCannotBeAdded;
class FileDoesNotExist extends FileCannotBeAdded
{
public static function create(string $path)
{
--->>>> return new static("File `{$path}` does not exist"); <<<<<----
}
}
i have use some solutions like clear cache,config,
php artisan storage:link....also changes storage path.Given bellow is my image uploading code in controller.i have use dropzone media library to upload images.
foreach ($request->input('prop_images', []) as $file) {
$addProperty->addMedia(storage_path('prop_images/' . $file))->toMediaCollection('prop_images');
}
thank you in advance... :)
I was having the same issue and in the end, it was an error in my logic, that was calling twice the temporary file so, correctly, it was giving error on the second time, as the temporary file had already been removed.
Basically, check your code for "addMediaFromRequest()" calls and review if it's more than one call trying to use THE SAME UPLOADED FILE, as it's going to break.
You can see more details at https://github.com/spatie/laravel-medialibrary/issues/1062
BadMethodCallException Method [getReport] does not exist.
But there is a method called getReport().
other reports are working but first one is not working. i wrote exactly the same codes.
There is a controller, but my laravel couldn't find it.
i tried:
php artisan route:clear
php artisan cache:clear
but it didn't work.
web.php->
Route::get('/report/{id}', 'ReportController#getReport');
Route::get('/report2/{id}', 'ReportController#getReport2');
ReportController.php ->
public function getReport(Request $request,$id)
{ $users=Users::find($id);
$pdf = PDF::loadView('admin.report', compact('users'));
return $pdf->stream(); }
codes are working on my pc (Localhost) But they are not working on Host (Website)
do it this way
public function getReport($id)
{
$users=Users::find($id);
$pdf = PDF::loadView('admin.report', compact('users'));
return $pdf->stream();
}
Laravel Controller doesn't exist, even though it clearly exists
it solved my problem...
Create a new file in app/controllers named TemplateController.php
Open up terminal and run composer dumpautoload -> This line solved my problem.
Thank You all
This laravel route is returning the image sometimes and is returning an error page the other times. What could go wrong.
This route just returns the image like this:
public function image(Request $request) {
return response()->file(storage_path('app/'.$request->input('path')));
}
I'm storing images using this code:
$path = $request->p->store('public/images');
Storage::setVisibility($path, 'public');
I don't know what's going wrong. I see this log when the route is requested.
NOTICE: PHP message: [2017-09-25 18:33:25] production.ERROR:
Symfony\Component\HttpFoundation\File\Exception\FileNotFoundException:
The file
"/app/storage/app/public/images/YxNllK0iVKAxxUSCEhFHLo5sGZiXg5NNbGDbOVSL.jpeg"
does not exist in /app/vendor/symfony/http-foundation/File/File.php:37
Here's the route in it's full glory:
https://resonant-tower-177816.appspot.com/showimage?path=public/images/YxNllK0iVKAxxUSCEhFHLo5sGZiXg5NNbGDbOVSL.jpeg
This is definitely not because there's no image there. I can assure you the route works some of the times.
What could have gone wrong?
I'm using Laravel 5.4 on Google App Engine.
Wrong path "/app/storage/app/public/images"
The correct path is like "/storage/app/public/images"
So you should change
public function image(Request $request) {
return response()->file(storage_path('app/'.$request->input('path')));
}
to
public function image(Request $request) {
return response()->file(storage_path($request->input('path')));
}
I have a laravel application that is still in the development stages. I am currently trying to generate a sitemap for the application using Spatie\Sitemap\SitemapGenerator but my code isn't working. This is my sitemap code in a file called GenerateSiteMap.php:
<?php
use Spatie\Sitemap\SitemapGenerator;
class GenerateSiteMap
{
public function generateSite()
{
$generator = SitemapGenerator::create('http://127.0.0.1:8000/')->writeToFile('sitemap.xml');
return $generator;
}
}
It doesn't give me any errors when I run it, it just doesn't do anything. Any idea how I can fix it?
If your file is at public folder you need to add public_path
$generator = SitemapGenerator::create('http://127.0.0.1:8000/')->writeToFile(
public_path('sitemap.xml'));
otherwise it might be a permission issue