Laravel PNG image shows but GIF image doesn't? - laravel

I have the following files in the public folder:
public/test.png
public/test.gif
In config/filesystems
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
The PNG file shows, the GIF doesn't (I get a 404). I ran php artisan storage:link and everything else is working fine, just the GIF files are not showing.

Make sure the path is correct. Names should be case sensitive (image.gif is not the same with image.Gif)

Related

How can I download fIles

I created a page where I can upload files to "/storage/app/public/uploads". I have a download button, which works fine on my XAMPP test environment. As I uploaded the project to the server, I still can upload files. They also go to the same directory "/storage/app/public/uploads". But when I want to download them, the download-path is /storage/uploads/ and I get a 404 error. But this is also on my XAMPP.
in my /config/filesystems.php i have
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
'links' => [
public_path('storage') => storage_path('app/public'),
],
]
I have no clue, what's wrong, because on my XAMPP it's fine. Any idea?
example can you create a new controller for example,
<a hrfe="{{route('downloadfile1')}}">download</a>
public function downloadfile1(){
$file=public_path()."/file1.pdf";
$headers = array(
'Content-Type: application/pdf',
);
return Response::download($file, 'filename.pdf', $headers);
}
Run php artisan storage:link on server to fix it.

Laravel 6- Mail not sending from localhost

It showing me this error
Expected response code 250 but got code "530", with the message "530-5.7.0 Authentication Required. Learn more at 530 5.7.0 https://support.google.com/mail/?p=WantAuthError
while I have enabled two-factor authentication and generated an app password.
here is my .env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=myemail#gmail.com
MAIL_PASSWORD=myAppGeneratedPassword
MAIL_ENCRYPTION=tls
and here is my mail.php
<?php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'myemail#gmail.com'),
'name' => env('MAIL_FROM_NAME', 'my_name'),
],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('myemail#gmail.com'),
'password' => env('appPassword'),
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/mail'),
],
],
];
Please help me. I am trying for three days.
Can you try with this config
MAIL_PORT=465
MAIL_ENCRYPTION=ssl

Laravel multi-tenant app works properly in local but does not work in production/staging

I build a multi-tenant app in laravel, That works properly in local but it does not work on production/staging. Whenever I try to login, it shows an error that : SQLSTATE[42S02]: Base table or view not found: 1146 Table 'tenancy.users' doesn't exist.
I have already run migrations and also try php artisan config:ca.
Package used : composer require "hyn/multi-tenant:5.3.*"
.env :
LIMIT_UUID_LENGTH_32=true
APP_URL_BASE=testdomain
APP_URL=http://${APP_URL_BASE}
DB_CONNECTION=system
TENANCY_HOST=127.0.0.1
TENANCY_PORT=3306
TENANCY_DATABASE=tenancy
TENANCY_USERNAME=root
TENANCY_PASSWORD=
database.php :
'default' => env('DB_CONNECTION', 'tenant'),
....
'system' => [
'driver' => 'mysql',
'host' => env('TENANCY_HOST', '127.0.0.1'),
'port' => env('TENANCY_PORT', '3306'),
'database' => env('TENANCY_DATABASE', 'tenancy'),
'username' => env('TENANCY_USERNAME', 'tenancy'),
'password' => env('TENANCY_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
'tenant' => [
'driver' => 'mysql',
'host' => env('TENANCY_HOST', '127.0.0.1'),
'port' => env('TENANCY_PORT', '3306'),
'database' => env('TENANCY_DATABASE', 'tenancy'),
'username' => env('TENANCY_USERNAME', 'tenancy'),
'password' => env('TENANCY_PASSWORD', ''),
'unix_socket' => env('DB_SOCKET', ''),
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
'prefix' => '',
'strict' => false,
'engine' => null,
],
.....
I also built a laraval mts, with laravel 8. It works locally and i have run into a similar issue.
ensure your .htaccess file is correct. Mine runs in cpanel and i found it was being overwritten everytime i updated the repo with master
make sure you have the databases set up. I use phpmyadmin on cpanel so i had to build the databases.
create a database user and give them access rights to the databases.
update .env to use your newly created database user

Laravel:Failed to retrieve image from storage

I have a function that store image to the storage/app/images
$filename = $image->getClientOriginalName();
if ($request->hasFile('image'))
{
$request->file('image')->storeAs('images', $filename);
}
$creator = new Content_form([
'media_id' => $request->get('media_name'),
'content_title' => $request->get('content_title'),
'content_description' => $request->get('content_description'),
'date_occured' =>\Carbon\Carbon::now()->format('Y-m-d'),
'page_number' => $request->get('page_number'),
'image' => $filename,
]);
$creator->save();
Image is stored in the database and in the storage/app/image only failed to retrieve those image here is my blade
#foreach($pendingNews as $number=> $post)
<td style="font-size: 16px; width: 210px"><img class="img-rounded" width="150" height="130" src="{{ asset('storage/app/images/'.$post->image) }}"></td>
#endforeach
Also file system I have
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'visibility' => 'public',
],
Remove /app from asset('storage/app/images/'.$post->image)

YII framework access environmental variables

In Laravel project we can create a file .env and store username and password as
.env file
DB_USERNAME=homestead
DB_PASSWORD=secret
And in database config/database.php
I can use it as
'mysql' => [
'driver' => 'mysql',
'host' => env('DB_HOST', 'localhost'),
'database' => env('DB_DATABASE', 'forge'),
'username' => env('DB_USERNAME', 'forge'),
'password' => env('DB_PASSWORD', ''),
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
'strict' => false,
],
How to do the same in YII framework
Laravel makes use of the PHP dotenv package - you can add it to Yii with Composer:
https://github.com/vlucas/phpdotenv
Note that env() is specific to Laravel, you'll need to use getenv() in Yii.

Resources