Laravel save image using dropzone.js into MySQL - mysql

I'm just trying out dropzone for the first time and would need assistance to set it up. I am getting error 500 thus:
Failed to load resource: the server responded with a status of 500 (Internal Server Error)
This is the controller:
public function storeDocument(Request $request){
$file = $request->file('file');
$fileName = uniqid().$file->getClientOriginalName();
$file->move('gallery/images', $fileName);
$productVerificationValidation = ProductVerificationValidation::findOrFail($request->productDocumentNameId);
$documentsUploaded = $productVerificationValidation->productDocumentUpload()->create([
'gallery_id' => $request->productDocumentNameId,
'user_id' => Auth::user()->id,
'company_id' => $request->company_id,
'product_id' => $request->product_id,
'file_name' => $fileName,
'file_size' => $file->getClientSize(),
'file_mime' => $file->getClientMimeType(),
'file_path' => 'gallery/images'. $fileName
]);
}
This is the route to store the image credentials:
Route::post('product/document/upload/save', array('before'=>'csrf', 'uses'=>'ProductVerificationValidationController#storeDocument'));
This is the form for Dropzone:
<form action="{{url('product/document/upload/save' )}}"
class="dropzone first-input-div" id="addImages">{{csrf_field()}}
{!!Form::hidden('productDocumentNameId', $productVerificationValidation->id)!!}
{!!Form::hidden('product_id', $productVerificationValidation->product_id)!!}
{!!Form::hidden('company_id', $productVerificationValidation->company_id)!!}</form>
This is the model setup:
public function productDocumentUpload(){
return $this->hasMany('App\ProductDocumentUpload');
}
I'm yet to understand what I need to do right. Please help out.

Related

Class Swift_Transport_Esmtp_Auth_CramMd5Authenticator does not exist

I can't seem to send an email with laravel 5.4 on after setting the right configurations in config/mail.php. I'm using smtp driver here is summary of my files.
Here is the config/mail.php
<?php
return [
'driver'=>env('MAIL_DRIVER', 'smtp'),
'host'=>env('MAIL_HOST', 'smtp.gmail.com'),
'port' => env('MAIL_PORT', 587),
'from' => [
'address' => env('MAIL_FROM_ADDRESS', 'info#afecamworld.org'),
'name' => env('MAIL_FROM_NAME', 'National President'),
],
'encryption' => env('MAIL_ENCRYPTION', 'ssl'),
'username' => env('MAIL_USERNAME', 'my-gmail-email'),
'password' => env('MAIL_PASSWORD', 'my-gmail-password'),
'sendmail' => '/usr/sbin/sendmail -bs',
'markdown' => [
'theme' => 'default',
'paths' => [
resource_path('views/vendor/mail'),
],
],
This is the SendActivationEmail class
<?php
use Illuminate\Bus\Queueable;
use Illuminate\Notifications\Notification;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Notifications\Messages\MailMessage;
class SendActivationEmail extends Notification {
use Queueable;
protected $token;
public function __construct($token) {
$this->token = $token;
}
public function via($notifiable){
return ['mail', 'database'];
}
public function toMail($notifiable) {
return (new MailMessage)->subject('Activation Your Account')->greeting('Hello!')->line('You need to activate your email before you can login.')->action('Activate Email', route('activate_account', ['token' => $this->token]))->line('Thank you for joining our Online Community!');
}
}
?>
This is the top part of the error
(1/1) ReflectionException
Class Swift_Transport_Esmtp_Auth_CramMd5Authenticator does not exist
in DependencyContainer.php (line 309)
I will be grateful for any help to resolve this error on dreamhost, thanks.
The best way to resolve this problem is to delete the files in the vendor folder and redo composer install and composer update, that's how I fixed my problem

Logstash - How to trigger Celery tasks through RabbitMQ

Can someone explain to me how I can trigger Celery tasks through Logstash?
Is it possible?
If I try to do that in PHP through the 'php-amqplib' library it works fine: (without using Logstash)
$connection = new AMQPStreamConnection(
'rabbitmq.local',
5672,
'guest',
'guest'
);
$channel = $connection->channel();
$channel->queue_declare(
'celery',
false,
true,
false,
false
);
$taskId = rand(1000, 10000);
$props = array(
'content_type' => 'application/json',
'content_encoding' => 'utf-8',
);
$body = array(
'task' => 'process_next_task',
'lang' => 'py',
'args' => array('ktest' => 'vtest'),
'kwargs' => array('ktest' => 'vtest'),
'origin' => '#'.'mytest',
'id' => $taskId,
);
$msg = new AMQPMessage(json_encode($body), $props);
$channel->basic_publish($msg, 'celery', 'celery');
According to the Celery docs:
http://docs.celeryproject.org/en/latest/internals/protocol.html
I'm trying to send the request in the json format, this is my Logstash filter:
ruby
{
remove_field => ['headers', '#timestamp', '#version', 'host', 'type']
code => "
event.set('properties',
{
:content_type => 'application/json',
:content_encoding => 'utf-8'
})
"
}
And Celery answer is:
[2017-05-05 14:35:09,090: WARNING/MainProcess] Received and deleted unknown message. Wrong destination?!
{content_type:None content_encoding:None delivery_info:{'exchange': 'celery', 'routing_key': 'celery', 'redelivered': False, 'consumer_tag': 'None4', 'delivery_tag': 66} headers={}}
Basically, Celery is not able to decode my message format or better... I'm not able to set the request in the JSON format :)
It's driving me crazy, thank you in advance for any clues :)
Forgot it, this is my output plugin in Logstash
rabbitmq
{
key => "celery"
exchange => "celery"
exchange_type => "direct"
user => "${RABBITMQ_USER}"
password => "${RABBITMQ_PASSWORD}"
host => "${RABBITMQ_HOST}"
port => "${RABBITMQ_PORT}"
durable => true
persistent => true
codec => json
}
From the information provided in this question, you can't.
When you're playing with the event in the ruby filter, you're actually playing with what will be put in the body of the message, while you'd like to set the rabbitmq headers and properties of your message.
Till that functionality has been tackled, I do not think you'll be able to achieve it unless of course you implement it yourself. After all, the plugin is available on github.
As Olivier said, right now is not possible but I've created a pull request to the official project.
https://github.com/logstash-plugins/logstash-output-rabbitmq/pull/59
If you are looking for a working version take a look to my clone:
https://github.com/useless-stuff/logstash-output-rabbitmq
You should be seriously scared about that code :)
I'm completely far away to be a Ruby developer
But it works :)

Through an error using Unisharp laravel file manager

i have update laravel 5.3 to 5.4 than i got this error for using laravel filemanager package Unisharp.
FatalErrorException in ItemsController.php line 0: Method
Illuminate\View\View::__toString() must not throw an exception, caught
ErrorException: Cannot use object of type stdClass as array (View:
ProjectName\resources\views\vendor\laravel-filemanager\item.blade.php)
(View:
ProjectName\resources\views\vendor\laravel-filemanager\item.blade.php)
return [
'html' => (string)view($this->getView())->with([
'files' => $files,
'directories' => $directories,
'items' => array_merge($directories, $files)
]),
'working_dir' => parent::getInternalPath($path)
];
add in the vendor views item.blade.php in the line 0
<?php $file = json_decode(json_encode($file),true) ; ?>

Fatal error: Class 'mPDF' not found in myproject/vendor/kartik-v/yii2-mpdf/Pdf.php on line 281

I have used kartik pdf extension to print my report in pdf format.Things are going well in my local computer but when i put my codes in server error appears like this:
Fatal error: Class 'mPDF' not found in myproject/vendor/kartik-v/yii2-mpdf/Pdf.php on line 281
In server i have uploaded yii2-mpdf folder inside kartik-v folder and also mpdf folder.
My code of controller for pdf print:
use kartik\mpdf\Pdf;
public function actionPearlFinancialReport()
{
$pdf = new Pdf([
//'mode' => Pdf::MODE_CORE,
'mode' => Pdf::MODE_UTF8,
'format' => Pdf::FORMAT_A4,
'orientation' => Pdf::ORIENT_PORTRAIT,
'destination' => Pdf::DEST_BROWSER,
'content' => $this->renderPartial('_financial_report', ['model' => $model,'parameter'=>$parameter]),
'cssFile' => '#vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',
'cssInline'=> '.kv-heading-1{font-size:15px;text-align:center;}',
'options' => ['title' => 'Pearl Financial Report'],
'methods' => [
'SetHeader'=>['Pearl Financial Report'],
'SetFooter'=>['{PAGENO}'],
]
]);
$response = Yii::$app->response;
$response->format = \yii\web\Response::FORMAT_RAW;
$headers = Yii::$app->response->headers;
$headers->add('Content-Type', 'application/pdf');
}
What to do?
Try this
'cssFile' => '#vendor/kartik-v/yii2-mpdf/src/assets/kv-mpdf-bootstrap.min.css',
Try to register this extension with composer:
For example my work directory is c:\xampp\htdocs\my-project
In a command prompt -> cd c:\xampp\htdocs\my-project
And register with this command:
C:\xampp\htdocs\my-project>php c:\xampp\htdocs\composer.phar require kartik-v/yii2-mpdf "dev-master"
I always register kartik's extensions with this metod, I hope want to be useful for you too.

Google_Http_REST::decodeHttpResponse throws exception unexpectedly

We are using PHP client: "google/apiclient": "1.0.4-beta" to upload a CSV to our google drive. Our script was working before, but stop working now. We haven't change anything. We tried dev, staging, production Google Product ID, all throw same error. Is there any problem on API side ? or there is some problem on our script ?
Exception :
#0 /home/dev/workspace/fb/vendor/google/apiclient/src/Google/Http/REST.php(44): Google_Http_REST::decodeHttpResponse(Object(Google_Http_Request))
#1 /home/dev/workspace/fb/vendor/google/apiclient/src/Google/Client.php(499): Google_Http_REST::execute(Object(Google_Client), Object(Google_Http_Request))
#2 /home/dev/workspace/fb/vendor/google/apiclient/src/Google/Service/Resource.php(195): Google_Client->execute(Object(Google_Http_Request))
#3 /home/dev/workspace/fb/vendor/google/apiclient/src/Google/Service/Drive.php(1694): Google_Service_Resource->call('insert', Array, 'Google_Service_...')
#4 /home/dev/workspace/fb/app/modules/Core/Models/Report/Generator/Spreadsheet/Google.php(53): Google_Service_Drive_Files_Resource->insert(Object(Google_Service_Drive_DriveFile), Array)
#5 /home/dev/workspace/fb/app/modules/Core/Models/Report/Manager.php(69): Core\Models\Report\Generator\Spreadsheet\Google->insert('report_21_test_...', Array)
#6 /home/dev/workspace/fb/app/modules/Core/Commands/Report/GenerateByQuery.php(55):
......
Our Code:
$client = new \Google_Client();
$client->setClientId($apiConfig['clientId']);
$client->setAssertionCredentials(new \Google_Auth_AssertionCredentials(
$apiConfig['accountName'],
array('https://www.googleapis.com/auth/drive'),
$key
));
$this->service = new \Google_Service_Drive($client);
$date = date("Y-m-d H:i:s");
// slice to max rows
$data = array_slice($data, 0, self::MAX_ROWS);
// generate spreadsheet with filename and data
$file = new \Google_Service_Drive_DriveFile();
$file->setTitle("$filename");
$file->setDescription("Report generate at $date");
$file->setMimeType(self::MIME_TYPE_ORIGINAL);
$csvStr = $this->getCsvString($data);
$createdFile = $this->service->files->insert($file, array(
'data' => $csvStr,
'mimeType' => self::MIME_TYPE_GOOGLE,
'uploadType' => 'multipart',
'convert' => true,
)); // exception is from here
// set permission
$this->service->permissions->insert($createdFile->getId(), $this->getPermission());
This was a temporary problem and it is now fixed.