Laravel route issue in subfolder - laravel

I have installed laravel 5.4 app at https://wolvecapital.com/muazzamazaz/
its getting web page of https://wolvecapital.com after login or register
For example inside web.php
Route::post('/sign_in' , 'UserApiController#signin'); this should get web page inside muazzamazaz resources but it getting main website page
I have put public folder files at root of muazzamazaz and all other files inside muazzamazaz/justcabbie folder
path setting inside index.php is:
require __DIR__.'/justcabbie/bootstrap/autoload.php';
and
$app = require_once __DIR__.'/justcabbie/bootstrap/app.php';
all other settings are not changed
filesystem.php is:
'local' => [
'driver' => 'local',
'root' => storage_path('app/public'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'visibility' => 'public',
],
since files are also not being stored in directory

Related

Laravel storage link doesnt link with public

Try to upload my files to storage, and link it with my public folder.
I used
php artisan storage:link
Then, I upload photos like below;
$filename = uniqid().".".$file->getClientOriginalExtension();
$filePath = 'uploads/announcement';
Storage::disk('public')->putFileAs($filePath, $file, $filename, ['visibility' => 'public']);
$announcement->photo = $filename ?? $announcement->filename;
But my /public/storage folder is empty, when I upload files.
Whats wrong with it?
My filesystem.php is below;
'public' => [
'driver' => 'local',
'root' => storage_path(),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
this is the way i do it (i n livewire but the storePubliclyAs Is not livewire)
if($this->image != null){
$imageName = time().'.'.$this->image->extension();
$company->image= $imageName;
// on upload l image dans le folder
$this->image->storePubliclyAs('companylogos',$imageName);
}
companylogos is the name of the folder in (storage/app)
i had same problem as you first ! you need to make sure your folder is linked , for that you need to see a little logo on the folder like a link logo meaning that the two folders are sync (linked) , the error is to create both files and try to link them , no you have to create only the storage/app/companylogos folder first and then use artisan to link php artisan storage:link
of course you need to have prepared your file in config filesystems, this is how i did it
'links' => [
public_path('storage') => storage_path('app/public'),
public_path('profilecv') => storage_path('app/profilecv'),
public_path('companylogos') => storage_path('app/companylogos'),
],
I think you have to change file system
filesystem.php is below;
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],

Laravel file from storage not found

Filesystem settings
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
Upload file
$path = $request->file('file-upload-photo-profile')->store('public/profile');
$user->photo_profile_url = Storage::url($path);
Patch to folder with file:
storage/app/public/profile
Example url:
Try get image:
<img src="{{asset( $user->photo_profile_url)}}" >
Generated url:
http://sakura/storage/profile/aDtjR6z7Ih4fkmo7bdAqqyDXmhu2qE4pg3s5BBla.jpg
But I got 404 for this image.
In server settings root dirrectory
public
How do I get a link to an image?
Do you have the symlink to the storage folder in your app/public directory?
Like so: php artisan storage:link

Shared Hosting Laravel 8 Hosting problem: Symlink is not working

I need the deploy my laravel project to the web. With this introduction But the hosting provider is Doesn't allow me to use a symbolic link(symlink), I called customer service, and told me blocked for security reasons.
So, since I do not use symbolic links, there are big problems in uploading images and deploying them.
Is there a way to do deployment my app?
Change your disk configurations in the config/filesystems.php to read and write to public folder via public_path() function.
If you're deploying over a shared host, you probably have another folder like public_html as your public folder which is not included in your source. Try to link to the public_html using dots ../../public_html/
'public' => [
'driver' => 'local',
// 'root' => storage_path('app/public'),
'root' => public_path(),
'url' => env('APP_URL'),
'visibility' => 'public',
],
'photos' => [
'driver' => 'local',
'root' => public_path('photos'),
'url' => env('APP_URL') . '/photos',
'visibility' => 'public',
],
Another way is just create something like symlink using php, example you can create a route like below:
Route::get(
'/storage/{file}',
function ($file) {
$filepath = "../storage/app/public/".$file;
header("Cache-Control: public");
header("Content-Type: ".mime_content_type($filepath));
header('Content-Length: '.filesize($filepath));
readfile($filepath);
die();
}
);
Maybe not best practice, but it will solve your problem. It's will do same as symlink.

How can i upload image from project 1 to project 2 with laravel?

I created 2 Laravel projects 1 for back-end and the second for the front-end.
So what i need to do is to upload images from back-end to front-end using Laravel store method.
My code:
if ($request->hasFile('image')) {
$path = $request->file('image')->store('images', 'domainPath');
$attributes['image'] = $path;
}
in the filesystems.php i added:
'domainPath' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_DOMAIN').'/storage',
'visibility' => 'public',
],
in the env file i add APP_DOMAIN = front-end absolute path which is:
D:/wamp64/www/projects/beytiresidence

Illuminate\Contracts\Filesystem\FileNotFoundException in Laravel 5.6 using Storage facade

This code is returning an strange error:
$file = Storage::get(Storage::disk('notas_xml')->path('') . 't.txt');
As you can see the file does exist.
Get the file directly from the disk
$exists = Storage::disk('notas_xml')->exists('t.txt');
if ($exists) {
$file = Storage::disk('notas_xml')->get('t.txt');
}
And if you didn't setup notas_xml disk in filesystems.php
$file = Storage::get('public/arquivos/notas_xml/t.txt');
And to use your code, you need to setup a disk like so in config/filesystems.php
'notas_xml' => [
'driver' => 'local',
'root' => storage_path('app/public/arquivos/notas_xml'),
'url' => env('APP_URL') . '/storage',
'visibility' => 'public',
],
And get the file simply like this
$file = Storage::disk('notas_xml')->get('t.txt');
You need to get the file as below code:
Storage::disk('notas_xml')->has('t.txt');
Above has method may be used to determine if a given file exists on the disk:
Please read documentation https://laravel.com/docs/5.1/filesystem#retrieving-files
To better understand all this... The trick is in: config/filesystems.php
If you have this code (which is the default value of Laravel in Github)
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
This Facade Storage will act in the folders
root_laravel_project/storage/app
So if you want to check if an "israel.txt" file exists
if( Storage::exists('israel.txt') ){
echo "File found. And it exists on the path: root_laravel_project/storage/app/israel.txt";
}
Remember that up to this point it has nothing to do with the symbolic link php artisan storage: link
This symbolic link is only to make a folder called "public" within the "storage" folder be part of the public access through HTTP
'disks' => [
'local' => [
'driver' => 'local',
'root' => storage_path('app'),
],
'public' => [
'driver' => 'local',
'root' => storage_path('app/public'),
'url' => env('APP_URL').'/storage',
'visibility' => 'public',
],
Then at the time of doing the sym. You can access the files by http (which are public for any user)
This example assumes that you are using a virtual host (and if not, you must do it as a recommendation for work better locally)
http:// root_laravel_project.test/storage/israel-alvarez.txt
Or so that it is better understood as in the old school without a virtual host
http:// localhost/public/storage/israel-alvarez.txt
Then these urls will look inside your folder
root_laravel_project/storage/app/public/israel-alvarez.txt
Laravel's documentation is somewhat brief and can be confusing regarding this issue. But you just have to remember that one thing is to access through the "storage Facade" (which is the correct way to upload and verify if there are files) and another thing is to access through the http (through url) which is the symbolic link (which is the treatment you already give to users to download files or see if it is a PDF for example).
I hope it helps. Good day

Resources