Does Laravel cache it's .env in anyway? I am having a weird problem - laravel

Sorry for this long post I don't have any other way to describe it in short.
I have two Laravel application which are hosted in two subdomains of the same domain. One is
form.example.com another is dashboard.example.com.
The Dashboard app sends a http request to the Form app to get some JSON data. And the code it uses to send the request is like this:
$url = "https://form.example.com/api/v2/get/orders/" . urlencode($log->lastpull);
$client = new \GuzzleHttp\Client();
$request = $client->request('GET', $url);
$json = $request->getBody();
$objects = (json_decode($json));
Now the problem is that Dashboard app sometimes get a blank JSON or some error message in return from the Form app when this request is made.
However the same code works file in the localhost and when I look up the URL (https://form.example.com/api/v2/get/orders/) I get a valid JSON object. Which indicates that Form app is fine.
The error message I talked about I get from the Form app as a response for the HTTP request is this:
SQLSTATE[42S02]: Base table or view not found: 1146 Table 'dbl5qxvxfrl9tl.products' doesn't exist (SQL: select * from `products` order by `index` asc)
The problem with this error message is that the database it mentions 'dbl5qxvxfrl9tl' belongs to the Dashboard app! The app which is making the request.
I have no idea why the Form app is looking for its table on the Dashboard app's database. It only occurs when I host the Dashboard app on my shared hosting's server. In localhost it works fine.
I tried to export the stack trace from the error page but for some reason it was not letting me to export. So I have saved the html page:
drive.google.com/file/d/1elbJhv4BpDNlxC2Ji_463dDLndjzjbm6/view?usp=sharing
(I have replaced the domain name in this html file for privacy reasons)

As user #apokryfos commented on the main post, solution to this problem is this:
If these are two separate Laravel apps in different paths then you can also try running php artisan config:cache on both of them to generate a cache for the config so it doesn't read environment variables anymore (in case there's some cross-over)

Related

How to stop the GET method is not supported for this route from showing?

I have a working Laravel project with loads of different routes.
I'm currently testing it and one of my tests was to check if a user were to use a delete or post route from the URL. I didn't know what the application would do honestly and it outputted the typical:
The GET method is not supported for this route. Supported methods: DELETE
which I have seen a million times. Is there a way to stop this error from coming up and instead output an error screen or simply redirect to a different view?
The error message:
The GET method is not supported for this route. Supported methods: DELETE.
should only appear when your Laravel site has APP_DEBUG set to true (in the .env file).
When APP_DEBUG is set to false as it should always be in on a live site, then the user will be shown a 404 error page instead.
You can easily test this by adding the following code to your routes file:
Route::delete('test', function() {
return 'You should never see this text when viewing url via a GET request';
});
May be u didn't noticed but ur form tag method attribute and route definition is different

Laravel api - 405 not allowed shared hosting

I'm new to Laravel and i have the next problem.
I have an API POST route that works properly in the localhost. I send POST requests from POSTMAN:
Route::group(['middleware' => 'api_import'], function () {
Route::get('/products', [ArticlesController::class, 'index']);
Route::post('/products', [ArticlesController::class, 'addOrUpdateArticles']);
Route::post('/categories', [CategoriesController::class, 'addOrUpdateCategories']);
});
However, it will not work on hosting. Hosting is shared, and I get the message:
When json contains a couple of products everything works properly. When json contains a complete table of 3500 products I get this error.
It is possible that there is a redirect on the page. You should confirm this through the network tab in your browser, because any POST request with a redirect is considered a GET request, so an error appears (405 Method Not Allowd)

Trying to set up CAS with my Laravel project

I am using subfission/cas for my application. I have followed all installation steps. I am using windows, if that matters. More precisely, I have configured the following:
I ran the following in my terminal
composer require "subfission/cas" "dev-master"
I configured my Kernel.php accordingly, adding the following:
'cas.auth' => 'Subfission\Cas\Middleware\CASAuth',
'cas.guest' => 'Subfission\Cas\Middleware\RedirectCASAuthenticated',
I ran the following command:
php artisan vendor:publish
I also set up my cas server in my cas.php config file:
'cas_hostname' => env('CAS_HOSTNAME', 'cas.myserver.me'),
'cas_real_hosts' => env('CAS_REAL_HOSTS', 'cas.myserver.me'),
What I want is a middleware for all my routes, so I added the following route rule in my routes:
Route::middleware(['cas.auth'])->group(function ()
{
Route::get('/', function ()
{
return view('welcome');
});
});
Basically, I want to redirect everyone who is not logged in to the login page whenever I access the main page (for now, I will add more routes in the future). What happens is that the users are redirected to the login page when they are not logged in, but after the login I receive the following error:
ErrorException (E_WARNING)
DOMDocument::loadXML(): Opening and ending tag mismatch: hr line 1 and body in Entity, line: 1
No matter what view I'm redirecting the user to. I tried the default welcome page as well as an empty view, but I still get the same error.
EDIT: I have used the dev-master branch from subfission/cas for the above error and after switching to 2.1.1, I get a different error:
session_name(): Cannot change session name when headers already sent
EDIT 2: I did some more digging and I enabled internal errors in my cas client class with:
libxml_use_internal_errors(true);
And now I get the following:
Authentication failure: SA not validated Reason: bad response from the CAS server
And the cas response is:
The thing is that I use the same cas server for another 2 projects and it works well for those (but those aren't laravel projects.
I know it's been a while, but for anyone else having issues like this, the issue is the protocol selected for which your web service communicates with your CAS(Central Authentication Service) provider. There are two main protocols used for SSO/CAS in this package:
SAML(Security Assertion Markup Language) version 1.1 & 2
CAS Protocol v3.0
[Confusingly enough, CAS protocol shares the same namespace as the service.]
The idea is to match the protocol and version with your identity provider. It sounds like your provider is using CASv3.0, which is why disabling SAML worked.
Also, if you enable debug mode, you will see further error details in your log file to help your troubleshoot.
Best of luck!
I managed to solve the issue by disabling the SAML in the cas configure file:
'cas_enable_saml' => env('CAS_ENABLE_SAML', true),
change to
'cas_enable_saml' => env('CAS_ENABLE_SAML', false),

Laravel 5.2 Incorrect Route Model Binding does not show 404

In Laravel 5.2 docs about Implicit route model binding, there is written:
If a matching model instance is not found in the database, a 404 HTTP
response will be automatically generated.
Route:
Route::get('/product/{product}',function(Product $product){
dd($product);
});
When I enter into URL parameter existent ID, everything works as expected. But when I enter into URL nonexistent product ID, I got No query results for model [App\Product]. instead of response 404. Any ideas why?
After searching i found out solution. If you have no specified error template files in resources/views/errors default Laravel message will be shown. Just create 404.blade.php file in resources/views/errors.

Laravel 4 - changing resource root routing path

In a Laravel 4 installation, Using Jeffrey Way's Laravel 4 Generators, I set up a 'tweet' resource, using the scaffolding command from his example:
php artisan generate:scaffold tweet --fields="author:string, body:text"
This generated the model, view, controller, migration and routing information for the tweet type. After migrating the database, visiting http://localhost:8000/tweets works fine, and shows the expected content.
The contents of the routes.php file at this point is:
Route::resource('tweets', 'TweetsController');
Now I would like to move the url for tweets up one level into admin/tweets, so the above url should become: http://localhost:8000/admin/tweets. Please note that I am not treating 'Admin' as a resource, but instead just want to add it for hypothetical organizational purposes.
Changing the routes.php file to:
Route::resource('admin/tweets', 'TweetsController');
Does not work, and displays the following error:
Unable to generate a URL for the named route "tweets.create" as such route does not exist.
Similarly when using the following:
Route::group(array('prefix' => 'admin'), function() {
Route::resource('tweets', 'TweetsController');
});
As was suggested in this stackoverflow question.
Using php artisan routes reveals that the named routes also now have admin prefixed to them, turning tweets.create into admin.tweets.create.
Why is the error saying that it cannot find tweets.create? shouldn't that automatically be resolved (judging by the routes table), to use admin.tweets.create?
How can I change my routing so that this error no longer occurs?
I just tested with new resource controller and it works fine for me.
The problem is not with the Route, its with the named routes used in your application.
check your view files there are link to route like link_to_route('tweets.create', 'Add new tweet'), this is creating the error because when you add admin as prefix tweets.create doesn't exists so change it to admin.tweets.create every where, in your controller also where ever named route is used.

Resources