Error throwing while sending an email using laravel [closed] - laravel

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 5 years ago.
Improve this question
Error throwing while sending an email using laravel after migration the web application to a new server. It was working fine on the previous server.
Relevant error description edited in from comments:
[2018-01-25 13:31:10] production.ERROR: ErrorException: mkdir(): No
such file or directory in
/var/www/html/jbservice/vendor/swiftmailer/swiftmailer/lib/c‌​lasses/Swift/KeyCach‌​e/Disk$
Stack trace: #0 [internal function]:
Illuminate\Foundation\Bootstrap\HandleExceptions->handleErro‌​r(2,
'mkdir(): No suc...', '/var/www/html/j...', 273, Array) #1
/var/www/html/jbservice/vendor/swiftmailer/swiftmailer/lib/c‌​lasses/Swift/KeyCach‌​e/DiskKeyCache.php(2‌​73):
mkdir('/tmp/68d392a3e3...')
Relevant code edited from comments:
Mail::send('dashboard.emails.createticket', $data , function ($message)
use ($data) { $message->subject('New Ticket: ' . $data['subject'])
->to("atif#gmail.com")
->from('HERE COMES THE SENDER EMAIL'); });

You can check your log.
If it show the SwiftMailer was trying to create cache in default /tmp folder :
To solve the issue, change the TMPDIR environment variable in the boot() method of app/Providers/AppServiveProvider.php.
/**
* Bootstrap any application services.
*
* #return void
*/
public function boot()
{
/**
* Somehow PHP is not able to write in default /tmp directory and SwiftMailer was failing.
* To overcome this situation, we set the TMPDIR environment variable to a new value.
*/
if (class_exists('Swift_Preferences')) {
\Swift_Preferences::getInstance()->setTempDir(storage_path().'/tmp');
} else {
\Log::warning('Class Swift_Preferences does not exists');
}
}
Please make sure that the new “tmp” folder location is writable by the web server.

Related

I cloned My KYC to Wallet Connect But its not working

Hello everyone please i clone my KYC Page to Wallet Connect, were users can submit information and it would reflect on the admin side just as the KYC works,i have duplicated everything and changed the names were its applicable but i am getting errors from the client side and the admin side, please i would be happy if you can assist me it would go a long way
enter image description hereI tried adding a wallet connect to my HYIP website and it'senter image description here returning this error
compact('type', 'operator', 'query', 'boolean');
in /home/investmentsite/public_html/app/Http/Controllers/Backend/WalletController.php (line 108)
* #return Application|Factory|View / public function edit($id) { $Wallet = Wallet::find($id); return view('backend.wallet.edit', compact('wallet')); } /* * Remove the specified resource from storage. *
enter image description here
The problem is that you variable is uppercase while you are passing a lowercase variable so just do either one of the following
compact('Wallet');
or change the variable name
$wallet = (...)
return view(...)->compact('wallet');
UPDATE 1#:
So from your comment my guess is that this will be your solution
$wallet = Wallet::findOrFail($id);
return view('backend.wallet.edit', compact('wallet'));

Laravel Homestead exception handling/pretty error message display not working

If there's an error anywhere in my code, such as in the routes file or a view, then instead of displaying the 'pretty' error message I get a dump of JS in the browser.
The error message is in there, but I have to hunt for it.
I'm using Laravel 5.8 in Homestead.
.env has APP_DEBUG=true set. I've also tried directly editing config/app.php to set debug but it doesn't work.
I'm quite new to Laravel so at a loss as to what to look at next...
Here's the first few lines of what gets dumped to the screen, please also check the attached screenshot below.
window.data = {"report":{"notifier":"Laravel Client","language":"PHP","framework_version":"6.0.3","language_version":"7.3.7-2+ubuntu18.04.1+deb.sury.org+1","exception_class":"Facade\\Ignition\\Exceptions\\ViewException","seen_at":1573633009,"message":"htmlspecialchars() expects parameter 1 to be string, array given (View: \/home\/vagrant\/pinyin\/resources\/views\/cards\/cards.blade.php)","glows":[],"solutions":[],"stacktrace":[{"line_number":251,"method":"handleError","class":"Illuminate\\Foundation\\Bootstrap\\HandleExceptions","code_snippet":{"236":"","237":"if (! function_exists(\u0027e\u0027)) {","238":" \/**","239":" * Encode HTML special characters in a string.","240":" *","241":" * #param \\Illuminate\\Contracts\\Support\\Htmlable|string $value","242":" * #param bool $doubleEncode","243":" * #return string","244":" *\/","245":" function e($value, $doubleEncode = true)","246":" {","247":" if ($value instanceof Htmlable)
Found the fix. In the webpack.mix.js file add the following to BrowserSync options:
mix.browserSync({
snippetOptions: {
rule: {
match: /<\/body>/i,
fn: function (snippet, match) {
return snippet + match;
}
}
}
});
Solution from: https://github.com/facade/ignition/issues/16#issuecomment-527260360
Found via: https://github.com/laravel/framework/issues/29909

Laravel 5.5 why is exception not thrown by foreign key violation from delete method?

Update 3: This problem from 9 months ago persists with Laravel 5.8 and Postgresql 11 on Windows 10 in a Laragon environment and Apache 2.4 on an Ubuntu machine. Does the Eloquent Model instance delete() method simply ignore foreign key constraints? It's baffling:
I have two tables in a Postgresql 9.3 database, companies and sites. There is a one-to-many relationship between them with companies on the one side. There is a foreign key constraint that prevents the deletion of a company if sites have been assigned to it. If I attempt to delete the company with the ID 'KSL' using an SQL query directly on the database, I get the expected error:
ERROR: update or delete on table "companies" violates foreign key constraint "sites_company_id_fkey" on table "sites"
DETAIL: Key (company_id)=(KSL) is still referenced from table "sites".
I have defined an artisan command whose handler method has a simple try/catch block:
public function handle()
{
$company = Company::find('KSL');
try{
$company->delete();
}catch(\PDOException $e){
$this->info($e->getMessage());
}
}
When I run the command from the console, I get the expected error message:
SQLSTATE[23503]: Foreign key violation: 7 ERROR: update or delete on table "companies" violates foreign key constraint "sites_company_id_fkey" on table "sites"
DETAIL: Key (company_id)=(KSL) is still referenced from table "sites". (SQL: delete from "companies" where "company_id" = KSL)
reflecting the native error message generated by Postgresql.
However, when I call the delete method from a Controller using an Ajax call using a similar try/catch block, the exception is not caught and the call fails with no details of the error.
I simplified the controller method to make it the same as the console handler:
public function deleteModel(Request $request) {
try {
$id = 'KSL';
$company = Company::find($id);
$result = $company->delete();
return 'success';
} catch (\PDOException $e) {
return $e->getMessage();
}
}
Normally I would get the value of $id from the request argument.
If I use a get request with a RESTful URL in the browser, I get a "The connection was reset" message in Firefox and a similar message in Chrome.
I have referred back to an old question of mine which I thought had the solution, but running composer dump-autoload had no effect. I have cleared the cache, re-installed Laravel 5.5, updated my installation, and called composer dump-autoload again several times but the absence of any exception or logged error message gives me no clue. Debug is set to true for this development app.
I passed a handler to the PHP native function register_shutdown_function like this in the autoload.php file in the bootstrap folder:
register_shutdown_function(function () {
$error = error_get_last();
file_put_contents(__DIR__.'/../storage/crash.log', var_export($error, true));
});
Only the word 'NULL' appears in the crash.log. I checked the Apache 2.4 error.log file and the specific error log for this Laravel app but there no relevant details recorded there.
Here is the Exception Handler:
<?php
namespace App\Exceptions;
use Exception;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
class Handler extends ExceptionHandler
{
/**
* A list of the exception types that are not reported.
*
* #var array
*/
protected $dontReport = [
//
];
/**
* A list of the inputs that are never flashed for validation exceptions.
*
* #var array
*/
protected $dontFlash = [
'password',
'password_confirmation',
];
/**
* Report or log an exception.
*
* This is a great spot to send exceptions to Sentry, Bugsnag, etc.
*
* #param \Exception $exception
* #return void
*/
public function report(Exception $exception)
{
parent::report($exception);
}
/**
* Render an exception into an HTTP response.
*
* #param \Illuminate\Http\Request $request
* #param \Exception $exception
* #return \Illuminate\Http\Response
*/
public function render($request, Exception $exception)
{
return parent::render($request, $exception);
}
}
UPDATE 1:
I got a clue from this question: Stack size for Apache under Windows. I quickly tested my online applications (all running on Linux machines) and there is no problem. The exception is thrown correctly and a nice clear message is displayed for the user. My local environment is Windows and it looks like Apache suffers from this connection reset error more than in a Linux environment. I've increased the stack size in Apache as suggested by the answer to that question but it still doesn't work. I still get a connection reset error. I've re-installed Apache with the latest binaries from Apache lounge I'm running PHP 7.3. Can anyone shed some light on this?
UPDATE 2:
An answer from Lucas to this question encouraged me to change server. When I ran php artisan serve from the console and then call the ParentTable->delete() method, I got the expected exception with no crashing. There is clearly something wrong with my Apache configuration. Unfortunately the accepted answer to that question doesn't solve my problem. I increased the stack size but the problem persists.

What causes an illegal offset in the makeAlias function of laravel 5.5 within this package implementation?

I am making packages for the first time in Laravel (v5.5). Unfortunately, the Route Model Bindings are giving me trouble. At first, I was receiving the id number raw without the model, and I realized that I had to force the package routes through the 'web' middleware grouping.
When I add the 'web' middleware grouping, I can see that laravel tries to load the model, but I receive an "Illegal offset type in isset or empty" in the first line of the Container->makeAlias method.
I have tried using custom binding loaders defined in the ServiceProvider using Route::model( $class, $closure ), but the error occurs before the loader is called. I've even tried moving this declaration from the ServiceProvider->boot method to the ServiceProvider->register method, just in case it is an order of operations issue.
I have tried adding a binding to the app by calling $this->app->bind inside the ServiceProvider, but this has had no effect.
I'm going to post the relevant code below, and I appreciate any insites that you may have! Thank you in advance!
Some Facts
The route
We are loading the url: http://127.0.0.1/profiles/1/edit for this test.
Operation without bindings
When no bindings or middleware are applied, and the url above is called, I can safely load the model from within the function manually and return the view. This indicates that the package is correctly loaded into the main application container.
The model can load in Tinker
To verify the model and database connection, we use tinker and run the command \Clemence\Profiles\Profile::find(1) to which the following is returned:
=> Clemence\Profiles\Profile {#777
id: 1,
name: "Clemence, Jared",
address: """
554 Christmas Tree Lane\n
Bakersfield, CA 93306
""",
email: "jaredclemence#gmail.com",
phone: "610-360-9558",
created_at: null,
updated_at: null,
deleted_at: null,
}
The stack trace
The Route->performBinding method is called with the following arguments:
[
Closure, /* Presumably the loader */
"1", /* the index that is passed into the route URL */
Route /* A self reference back to the containing object */
]
after this, the Closure is called with
[
"1",
Route
]
from the Closure, Application->make is called, the argument named $class is passed another Closure with the following definition:
Closure {#97 ▼
class: "Clemence\Profiles\ProfilesServiceProvider"
this: ProfilesServiceProvider {#87 …}
parameters: {▶}
}
lastly we end up in Container->makeAlias where the Exception is thrown, makeAlias is called with this Closure:
Closure {#97 ▼
class: "Clemence\Profiles\ProfilesServiceProvider"
this: ProfilesServiceProvider {#87 …}
parameters: {▶}
}
The Files
packages/clemence/profiles/src/routes.php
Route::group(['middleware' => ['web']], function() {
Route::get('/profiles/{profile}/edit', '\Clemence\Profiles\ProfileController#edit');
Route::get('/profiles/create', '\Clemence\Profiles\ProfileController#create');
Route::get('/profiles', '\Clemence\Profiles\ProfileController#showAll');
Route::get('/profiles/{profile}', '\Clemence\Profiles\ProfileController#show');
Route::post('/profiles/create', '\Clemence\Profiles\ProfileController#createWithFormData')->name('profile.create');
Route::put('/profiles/{profile}', '\Clemence\Profiles\ProfileController#updateWithFormData')->name('profile.update');
Route::delete('/profoiles/{profile}', '\Clemence\Profiles\ProfileController#destroy')->name('profile.delete');
Route::get('/roles', '\Clemence\Profiles\RoleController#showAll');
Route::get('/roles/{role_id}', '\Clemence\Profiles\RoleController#show');
Route::get('/roles/create', '\Clemence\Profiles\RoleController#create');
});
packages/clemence/profiles/src/ProfilesServiceProvider.php
namespace Clemence\Profiles;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Route;
class ProfilesServiceProvider extends ServiceProvider {
/**
* Bootstrap the application services.
*
* #return void
*/
public function boot() {
$this->loadRoutesFrom( __DIR__ . '/routes.php' );
if ($this->app->runningInConsole()) {
$this->commands([
\Clemence\Profiles\Commands\InstallProfiles::class,
\Clemence\Profiles\Commands\PrepareEnvironmentForProfiles::class
]);
}
}
/**
* Register the application services.
*
* #return void
*/
public function register() {
$this->app->make(\Clemence\Profiles\ProfileController::class);
$this->app->make(\Clemence\Profiles\RoleController::class);
$this->loadMigrationsFrom(__DIR__ . '/migrations');
$this->loadViewsFrom(__DIR__ . '/views', 'profiles');
}
}
packages/clemence/profile/src/ProfileController.php
namespace Clemence\Profiles;
use App\Http\Controllers\Controller;
use Clemence\Profiles\Profile;
use Illuminate\Http\Request;
use Clemence\Profiles\FormTemplateData;
use Illuminate\Support\Facades\URL;
class ProfileController extends Controller
{
/* ... collapsed ... */
/**
* Show the form for editing the specified resource.
*
* #param \App\Profile $profile
* #return \Illuminate\Http\Response
*/
public function edit(Profile $profile )
{
return dd( $profile );
$formData = new FormTemplateData();
$profile = Profile::find( $profile_id );
$formData->setProfile( $profile );
$formData->setFormActionMethod("POST");
$formData->setDeleteButtonText("Delete Profile");
$formData->setSubmitButtonText( "Update Profile" );
$on_cancel_route_url = $formData->getNamedUrl('profile.delete');
$on_submit_route_url = $formData->getNamedUrl('profile.update');
$formData->setFormCancelUrl($on_cancel_route_url);
$formData->setFormSubmitUrl($on_submit_route_url);
return $this->editForm($formData);
}
/* ... collapsed ... */
}
packages/clemence/profile/src/Profile.php
namespace Clemence\Profiles;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Eloquent\Model;
class Profile extends Model
{
use SoftDeletes;
}
RESOLVED: SOLUTION UNKNOWN
I will post the steps that I took to find the resolution here for those who may find this post in the future. I admit: I have no idea what fixed the problem.
What I did after asking the question
First and foremost, I got some sleep. When I have been coding too long, I find that sleep solves most problems.
On waking, I realized that I have a machine with XDebug installed and I can literally step through the PHP code as it executes, so I booted up that machine and did the following:
a. I moved the project to the local machine and opened it in NetBeans.
b. I placed breakpoints at several places in the middle ware so that I could verify that the system was running.
c. I changed the project config to run "as a website" and to load the url http://localhost:8000/profiles/1/edit as the start point.
d. I clicked 'Debug Program' and stepped through the bootup, the route loading, the model binding, and watched it all happen step-by-step looking for any line of code or parameter that looked out of sorts. I watched as the model was selected. I watched as it was passed the id 1 and asked to build the query. I watched as a collection of Profiles was returned (Oh! how excited I was to see the data I wanted sitting in that array and knowing that it was there but something would eventually block it, and I would find the block and release it!), and I watched as the collection was asked to return the first value. Then I watched as the parameter was set on the route. Lastly, I watched as the command $kernal->terminate() ran....
Needlessly to say, I was very disappointed and confused. How could I be getting an error, if the Kernal is running to completion?
So, I looked at the browser window, and there in the browser window was the very information that I was looking for! The Profile had loaded. I had changed nothing, and the Profile had loaded.
I moved the code back to the original machine, maybe it is an environment setting? I ran the web query without debugging, and it loaded... no error!
So, I honestly don't know what happened. I doubt that getting sleep helped the problem.
Maybe the Netbeans Debugger ran a cleanup service that fixed or patched a bad linkage? I honestly don't know, but I do know that this problem is resolved, so I post this answer in the hopes that it helps someone in the future, and that it saves other people the time of needlessly looking for an unnecessary solution.

Autoloader registery not found in autoload.php

I was facing an error while updating my magento 2 website, because of that error i can't able to do anything ex: i can't able to compile, update & deploy static content.
Here is the error:
PHP Fatal error: Uncaught Error: Class 'Magento\Framework\Autoload\AutoloaderRe gistry' not found in /var/www/vhosts/potboy.com.my/httpdocs/app/autoload.php:37
Stack trace:
#0 /var/www/vhosts/potboy.com.my/httpdocs/app/bootstrap.php(30): require_once()
#1 /var/www/vhosts/potboy.com.my/httpdocs/bin/magento(14): require('/var/www/vho sts...')
#2 {main}
thrown in /var/www/vhosts/potboy.com.my/httpdocs/app/autoload.php on line 37
Can anyone please help me to solve this issue. i already updated the composer but still the same error exists please find this screenshot for reference
.
here is my autoload file:
<?php
/**
* Register basic autoloader that uses include path
*
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
use Magento\Framework\Autoload\AutoloaderRegistry;
use Magento\Framework\Autoload\ClassLoaderWrapper;
/**
* Shortcut constant for the root directory
*/
define('BP', dirname(__DIR__));
define('VENDOR_PATH', BP . '/app/etc/vendor_path.php');
if (!file_exists(VENDOR_PATH)) {
throw new \Exception(
'We can\'t read some files that are required to run the Magento application. '
. 'This usually means file permissions are set incorrectly.'
);
}
$vendorDir = require VENDOR_PATH;
$vendorAutoload = BP . "/{$vendorDir}/autoload.php";
/* 'composer install' validation */
if (file_exists($vendorAutoload)) {
$composerAutoloader = include $vendorAutoload;
} else {
throw new \Exception(
'Vendor autoload is not found. Please run \'composer install\' under application root directory.'
);
}
AutoloaderRegistry::registerAutoloader(new ClassLoaderWrapper($composerAutoloader));
// Sets default autoload mappings, may be overridden in Bootstrap::create
\Magento\Framework\App\Bootstrap::populateAutoloader(BP, []);
It looks like Magento not find vendor/magento/framework/Autoload/AutoloaderRegistry.php
Can you check above file is there or not and if not than first run command "composer update" from the root of your Magento installation.

Resources