I'm using 5.5 larevel's version and postman to test the API.
I ran the command
php artisan passport:client --password
To generate id and secret. When I post localhost:8000/oauth/token
post:
it returns me a token but when I want to get an enpoints values its returns me Unauthenticated
here is route api.php
<?php
use Illuminate\Http\Request;
/*
|--------------------------------------------------------------------------
| API Routes
|--------------------------------------------------------------------------
|
| Here is where you can register API routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| is assigned the "api" middleware group. Enjoy building your API!
|
*/
Route::middleware('auth:api')->get('/users', function (Request $request) {
return $request->user();
});
Route::middleware('auth:api')->get('/subjects','SubjectController#index');
If you are in Apache server, I guess this should help you as it works on mine :
Just add these lines on your .htaccess file :
RewriteEngine On
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
as stated in this thread.
Hope that helps.
Check valid access_token.
In my case, Error occur because I just copied a part of access_token.
Ex:
access_token: eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImE2YWU0YjdjNjQzN2NhMjgxNTgxMGZhOGQ1ZmJmNDE5YzUwZDVhMzEyZmRiMzVmYTIyZjA0ZmZmMGQ0MDQxMzU2M2E1YWIyMGM1ODE3ZDAwIn0.eyJhdWQiOiI3IiwianRpIjoiYTZhZTRiN2M2NDM3Y2EyODE1ODEwZmE4ZDVmYmY0MTljNTBkNWEzMTJmZGIzNWZhMjJmMDRmZmYwZDQwNDEzNTYzYTVhYjIwYzU4MTdkMDAiLCJpYXQiOjE1MDczNTEyMjAsIm5iZiI6MTUwNzM1MTIyMCwiZXhwIjoxNTA4NjQ3MjIwLCJzdWIiOiI1OWNkODBlMGQxMzgyMS4zNDYyNDIxNyIsInNjb3BlcyI6WyIqIl19.4aC5jlHlqXYX9_StnwaU_4nSHUlum1gTuNGyKUyDoCs_1s-PYDMRD74gH1sG0l2B2TkGJjM_mHNSNTzQNKxSmHNGCncvQkpQtJQ9-iObJb0gWVHTwBz53GS5FNPcp6VlN5yX8qkZQLvt28uJTAzqdkqtKBt0592Lh7K2TIueRaytQKk_lRc6sud9WdYOojlNK37Og94adbX3nNbtiHKQ2WSsdJTP5IWhsQIRjgYEEhY9phtLdFAuFBK30lDQ3wshlcl4kPo9GBcjfZe0K5I_vISo0v9JzGHkf0xJynhx9SWPtFY4Ol1BwCKztfLiW2oyFLdGY-CKGpJo1iX5AQGmwqWeW6zP3gQ1JTRtpQy6X3HSrTu3TLWamZZWLaB1niIQ7w2jNIhc2NbEW0eUw7xSFuNiWvHneyAPC1FTPKSigL7qtS9_zOi80PHWxQ6yRdRWqiV3HqSYdjzQaLe-RCz4zABiaRP1-YLd0xCUMoGjRSTUOKFkOQSYiTdTYQq2bwHPwjHnmKRiyFRCyiGbTmgnZjQ2nPVSL16x3adg7s5ECk2LlSNrMykB-YVueY6i7M4wF993tmgBGyCtx_mIruFN8-I8vs0cbo2Pv1AFM7Tss1dZ8NMZJRW6mU5M_95AfeNphGpVJ6U4xFZBM6GoXP4yTx-zTBR7xWG404f9yJocqIE
But i coppied
eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsImp0aSI6ImE2YWU0YjdjNjQzN2NhMjgxNTgxMGZhOGQ1ZmJmNDE5YzUwZDVhMzEyZmRiMzVmYTIyZjA0ZmZmMGQ0MDQxMzU2M2E1YWIyMGM1ODE3ZDAwIn0
Related
I have a secret test key for a payment gateway in the .env file.
APP_TIMEZONE = 'Africa/Lagos'
APP_PAYSTACK_KEY = sk_test_b6c0b4925403blablabla
Reason is that other people working on the project can use their own test key if they have. So in a payment controller i get the value of this key like so:
"authorization: Bearer " .env('APP_PAYSTACK_KEY' , 'sk_test_b6c0b4925403blablabla')
During deployment I intend running config:cache so that Laravel won't be going a long trip in getting the required configuration setups. But from Laravel documentation :
If you execute the config:cache command during your deployment
process, you should be sure that you are only calling the env
function from within your configuration files. Once the configuration
has been cached, the .env file will not be loaded and all calls to
the env function will return null.
So my question is how can I set this APP_PAYSTACK_KEY in the config file and how to retrieve it anywhere in my app?
You can add paystack to your config/services.php file:
<?php
return [
/*
|--------------------------------------------------------------------------
| Third Party Services
|--------------------------------------------------------------------------
|
| This file is for storing the credentials for third party services such
| as Stripe, Mailgun, SparkPost and others. This file provides a sane
| default location for this type of information, allowing packages
| to have a conventional place to find your various credentials.
|
*/
// ...
'paystack' => [
'key' => env('APP_PAYSTACK_KEY', 'sk_test_b6c0b4925403blablabla'),
],
];
Then call config() helper method instead of env() on your controller:
"authorization: Bearer " .config('services.paystack.key')
Now you're safe to cache your configs via calling php artisan config:cache.
I am serving a file via Lumen route and URL contains dot and extension file. and when URL contains dot Lumen look for resources not executing routes.
I've tried to run it on production server and it works but on development environment it does not work.
This is my route:
$router->get('file/{file}', function (Request $request, $file) {
echo $file;
});
When I try to open this URL route will be run:
http://localhost:9001/file/photo.jpg
When I try to open this URL Lumen look for resources:
http://localhost:9001/file/photojpg
I want to create '/resources' route in Laravel but there is also directory called 'resources' in laravel so how to handle that ?
currently it is showing resources directory instead of executing route.
First of all, the default resources folder on laravel are in the root directory, not into public directory.
When you access a Laravel URL, eg. http://localhost/xyz, first the server will
search for a xyz file inside public folder, if it exists it will be served, otherwise the index.php will be called and then Laravel try to resolve the route.
solved by public/.htaccess
RewriteCond %{REQUEST_URI} /resources
RewriteRule ^ index.php [L]
I am having a bit of an issue with one route (and only with this one, every other route works without any issue).
This are my routes (I commented out all routes, except the /home, just to be sure that they are not messing up something):
<?php
// Route::get('/', 'DashboardController#index')->middleware('menu.admin')->name('home');
Route::get('/home', 'DashboardController#index')->middleware('menu.admin')->name('home');
// Route::get('/user/verify/{token}', 'Auth\RegisterController#verifyUser');
// Route::get('logout', '\App\Http\Controllers\Auth\LoginController#logout');
// Auth::routes();
// // Admin routes (admin dashboard)
// require(base_path() . '/routes/admin.php');
// // Site routes (frontend)
// require(base_path() . '/routes/front.php');
I am getting this error:
Not Found
The requested resource /home was not found on this server.
The / route works without any issues, and when I try /home (the only difference between this two routes), I am getting the error.
I did php artisan route:clear, and it didn't help. Does anyone have an idea what is going on (.htaccess file is not an issue here)?
Laravel ^5.6
if your routes are defined properly, and by properly i mean you defineded routes in the right order (to avoid conflicts) and the artisan command php artisan route:list get executed correctly BUT you still get 404 Not found - The requested resource /path was not found on this server. weird, not exactly what you were expecting!!
...i also faced this problem, and here is the thing, that error occurs when you create a folder in the public directory with the same URI
...to illustrate here's an example (this is the problem i faced)
routes/web.php
/*
|--------------------------------------------------------------------------
| Web Routes - Backend
|--------------------------------------------------------------------------
*/
Route::group(['namespace' => 'Backend', 'prefix' => 'backend'], function () {
Route::get('/', 'DashboardController')->name('backend.dashboard');
// ...
});
php artisan route:list
php artisan route:list --name=backend --columns=uri --columns=name
+--------------------------------+--------------------------------------+
| URI | Name |
+--------------------------------+--------------------------------------+
| backend | backend.dashboard |
| // ... | // ... |
+--------------------------------+--------------------------------------+
public/
+---public
| +---backend
| | +---css
| | +---fonts
| | +---images
| | +---js
| +---.htaccess
| +---favicon.ico
| +---index.php
| +---mix-manifest.json
| +---robots.txt
As you can see, i have a route URI that start with backend AND also a folder under the public directory named backend as well, that's what cause the problem, so it's up to you to change one of those, personally i changed the name of the folder under public directory to "back-end". that solved my problem.
you use apache or nginx as web server?
try to set config for webserver
https://laravel.com/docs/5.6/installation
Because, you have a folder named control on /public folder. That error occurs when you create a folder in the public folder with the same name as your route so please change the name of the folder you have put in the public folder so that it has a different name from your route this will probably solve your error
my server using cPanel. directory structure here
laravel-project
public_ftp
public_html
public
index.php
I deployed on the server following this guy
https://github.com/petehouston/laravel-deploy-on-shared-hosting
everything well but my base path is "mydomain.com/public"
I don't want to remove /public out from my path but to change it,
I want path like this "mydomain.com/noticed"
I using laravel version 5.3
Any Idea?
Thank You
In laravel 5.6 add this code to bootstrap/app.php :
$app->bind('path.public', function() {
return realpath(__DIR__.'/../');
});
where __DIR__.'/../' is path to your public folder
It was suggested to change the index.php in your public folder.
*
|--------------------------------------------------------------------------
| Turn On The Lights
|--------------------------------------------------------------------------
|
| We need to illuminate PHP development, so let us turn on the lights.
| This bootstraps the framework and gets it ready for use, then it
| will load up this application so that we can run it and send
| the responses back to the browser and delight our users.
|
*/
$app = require_once __DIR__.'/../bootstrap/app.php';
// set the public path to this directory
$app->bind('path.public', function() {
return __DIR__;
});
Now you dont need to change your public path when your public
directory has changed.
Elixir has a hardcoded public path! Do not forget to set the changed
public path in the Elixir config.
I might add that you also need to make sure that your new public path have the same permission as the default one. You might also want to change the public path in the config/filesystem.php.