I have to download some files from my webapp with laravel 5.6 and I am using the local storage.
I have my routes like downloads/{file} with the auth middleware and it's working properly.
The storage url is the default from laravel www.myweb.com/storage/files/ ...
the thing is if I use the route www.myweb.com/downloads/foo.pdf the controller is working properly and i must be logged in to download the file
but if I access from www.myweb.com/storage/files/foo.pdf I can see the file without being logged in
How can i solve this? should i create another controller or route to handle this?
should i create a route like
Route::get('/storage/files/{file}', 'FilesController#download')->middleware('auth');
/storage/files is already actual path of the storage. to avoid conflict change your route to other path
Route::get('/storage/files/{file}', 'FilesController#download')->middleware('auth');
change to (sample)
Route::get('/files/{file}/download', 'FilesController#download')->middleware('auth');
then do your logic in FilesController
Related
I am currently working on an API only laravel application. In the controllers folder, there is an API folder that holds all controllers. The ForgotPasswordController is in the API folder as well.
When I run the command php artisan route:list I get the error below
Illuminate\Contracts\Container\BindingResolutionException : Target class [App\Http\Controllers\Auth\ForgotPasswordController] does not exist.
There is actually no ForgotPasswordController in the Auth folder. How do I handle this issue?
You have to make sure you are doing php artisan route:cache priority.
If the problem still persists, can you disable the auth provider and try?
For the sake of time considering that the project is live and I need to churn out a couple of features, I have moved both ForgotPassword and ResetPassword controllers back into the Auth folder. Ran a test to make sure nothing has been broken (everything works fine) and now I am able to list out the routes.
If you have Auth::routes() or Route::auth() in your routes file that would be generating routes to the ForgotPasswordController.
You would need to not be calling that or you would need to pass the proper option to it to have it not register those routes:
Auth::routes(['reset' => false]);
Depending on the version you are using this may not work. If that is the case you will have to not use this method at all and register the routes you want/need yourself.
Laravel 5.7
PHP 7.2
DB mysql
already see https://laravel.com/docs/5.7/filesystem
I am using the Local Driver.
after some process, I have set a image to public file.
e.g.
https://127.0.0.1/storage/myViewFile/0120020301-3.png
I want to set only can view dir "myView File" after login.
How can I do it? thank you.
Route::get('/storage/files/{file}', 'FilesController#show')->middleware('auth');
and in the show method display the image.
If you were to use your local driver and would want to make files accessible in your storage folder then you would run an artisan command like below
php artisan storage:link
This will ensure that files are accessible publicly as example.com/public/storage/whateverfile. However, if you want the files to be only accessible to authenticated user then may be you can put the files in storage/myViewFile which will make sure that files in the folder aren't publicly accessible. Then using a controller with an auth middleware or route with middleware you can make files accessible
Is there any way to get session variable/data outside of the laravel application?
I have a project in core php (e.g: myproject) directory and now I want to signup/signin from laravel which will be placed in internal directory (e.g: myproject/laravel). I want to get signed-in user's details through session in myproject directory.
Is there any way/alternate for that?
You will have to add session_start(); in public/index.php on the top.
After that still need to set your external sessions in the classic way $_['mysession'] = 'something';. Remember that this will not work if you want to access auth() methods outside Laravel.
I am in the process of installing SimpleSAML and in the php library, there is a folder called www that has index.php. According to the docs, there is an admin console within it. However, at the moment I am unable to access it via the url www.website.com/third_party/simplesaml/www/index.php.
I am supposed to use the admin console to generate some metadata so I'm just wondering if it is possible to route to a view from there?
I'm thinking that I create a controller and just hard link $this->load->view('url to www') but I'm not sure if that works.
In controller’s constructor add
include APPPATH . 'third_party/simplesaml/www/index.php';
to include the file in your project.
you can set base path in route file and instead of $this->load->view() you can use renderView() function to access view in codeigniter.
I'm doing a laravel app but when I try to create an account it gives a csrf error..
When I check what cookies the website have, I find that I have no cookies, there should be a XSFR-TOKEN and a laravel_session cookies, but laravel is not generating any of those cookies, so it gives me a token not found when i try to create an account.. anyone know why it does that? any idea how to fix that?
Also just installed a new clean laravel and find out if I put the "app" view inside of a folder it also happends and doesnt generate the cookies, I have tried to change the folder permissions but the problem persists.
Open your http app/Http/Kernel.php file and check if your Kernel::$middleware array contains:
Illuminate\Cookie\Middleware\EncryptCookies
Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse
Illuminate\Session\Middleware\StartSession (this is middleware which is responsible for passing data to session driver in Laravel 5)
Illuminate\View\Middleware\ShareErrorsFromSession
App\Http\Middleware\VerifyCsrfToken
To clarify - Kernel::$middleware array contains middleware which is executed on every HTTP request. By default it contains middleware that is essential for session support in Laravel. Perhaphs you accidentaly deleted them.
Here is original file: https://github.com/laravel/laravel/blob/v5.0.22/app/Http/Kernel.php