When try to make a new migration table with posts it shows following error - migration

$ php artisan migrate
Error
Class "CreatePostsTable" not found
at E:\Xampp\htdocs\Udemy\vendor\laravel\framework\src\Illuminate\Database\Migrations\Migrator.php:453
449▕ public function resolve($file)
450▕ {
451▕ $class = Str::studly(implode('', array_slice(explode('', $file), 4)));
452▕
➜ 453▕ return new $class;
454▕ }
455▕
456▕ /**
457▕ * Get all of the migration files in a given path.
1 E:\Xampp\htdocs\Udemy\vendor\laravel\framework\src\Illuminate\Database\Migrations\Migrator.php:189
Illuminate\Database\Migrations\Migrator::resolve("2020_12_29_055715_create_posts_table")
2 E:\Xampp\htdocs\Udemy\vendor\laravel\framework\src\Illuminate\Database\Migrations\Migrator.php:165
Illuminate\Database\Migrations\Migrator::runUp("E:\Xampp\htdocs\Udemy\database\migrations/2020_12_29_055715_create_posts_table.php")

Related

Laravel Redis read error on connection to 127.0.0.1:6379

Testing Redis pub/sub in my Laravel app. Executing this artisan command
public function callback(){
print_r(func_get_args());
}
public function handle(): int
{
$client = Redis::connection()->client();
if($client->isConnected()){
$this->line('Connected'); // Prints "Connected"
}
$client->subscribe(['exchanges'], [$this, 'callback']);
$client->publish('exchanges', json_encode($this->getExchanges()));
return 0;
}
gives this error:
read error on connection to 127.0.0.1:6379
at app/Console/Commands/Client/Start.php:49
45▕ if($client->isConnected()){
46▕ $this->line('Connected');
47▕ }
48▕
➜ 49▕ $client->subscribe(['exchanges'], [$this, 'callback']);
50▕ $client->publish('exchanges', json_encode($this->getExchanges()));
51▕
52▕ return 0;
53▕
1 app/Console/Commands/Client/Start.php:49
Redis::subscribe()
Whats wrong with subscribe() method?
ini_set('default_socket_timeout', -1) Works for me.

laravel 7 pdf-to-text | Could not read pdf file

I installed this laravel package to convert pdf file into text. https://github.com/spatie/pdf-to-text
I'm getting this error:
Could not read sample_1610656868.pdf
I tried passing the file statically by putting it in public folder and by giving path of uploaded file.
Here's my controller:
public function pdftotext(Request $request)
{
if($request->hasFile('file'))
{
// Get the file with extension
$filenameWithExt = $request->file('file')->getClientOriginalName();
//Get the file name
$filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
//Get the ext
$extension = $request->file('file')->getClientOriginalExtension();
//File name to store
$fileNameToStore = $filename.'_'.time().'.'.$extension;
//Upload File
$path = $request->file('file')->storeAS('public/ebutifier/pdf', $fileNameToStore);
}
// dd($path);
$location = public_path($path);
// $pdf = $request->input('file');
// dd($location);
// echo Pdf::getText($location, 'usr/bin/pdftotext');
$text = (new Pdf('public/ebutifier/pdf/'))
->setPdf($fileNameToStore)
->text();
return $text;
}
Not sure why it's not working any help would be appreciated.
You used spatie/pdf-to-text Package.
I also tried to use this package but it gave me this kind of error.
So, I used asika/pdf2text package and it worked properly
Asika/pdf2text pacakge
And this is my code
$path = public_path('/uploads/documents/'. $file_name);
$reader = new \Asika\Pdf2text;
$output = $reader->decode($path);
dd($output);
Hopefully, it will be helpful for you.

Drupal 8: When I update the node field to a specific value, how to call my module (managefinishdate.module) to update another field?

I am having a node type with machine name to_do_item, and I want to create a module called managefinishdate to update the node: when a user edit the node's field (field_status) to "completed" and click "save", then the module will auto update the field_date_finished to current date.
I have tried to create the module and already success to install in "Extend":
function managefinishdate_todolist_update(\Drupal\Core\Entity\EntityInterface $entity) {
...
}
however, I am not sure is this module being called, because whatever I echo inside, seems nothing appeared.
<?php
use Drupal\Core\Entity\EntityInterface;
use Drupal\node\Entity\Node;
/** * Implements hook_ENTITY_TYPE_update().
* If a user update status to Completed,
* update the finished date as save date
*/
function managefinishdate_todolist_update(\Drupal\Core\Entity\EntityInterface $entity) {
$node = \Drupal::routeMatch()->getParameter('node');
print_r($node);
//$entity_type = 'node';
//$bundles = ['to_do_item'];
//$fld_finishdate = 'field_date_finished';
//if ($entity->getEntityTypeId() != $entity_type || !in_array($entity->bundle(), $bundles)) {
//return;
//}
//$current_date=date("Y-m-d");
//$entity->{$fld_finishdate}->setValue($current_date);
}
Following Drupal convention, your module named 'manage_finish_date' should contain a 'manage_finish_date.module file that sits in the root directory that should look like this:
<?php
use Drupal\node\Entity\Node;
/**
* Implements hook_ENTITY_TYPE_insert().
*/
function manage_finish_date_node_insert(Node $node) {
ManageFinishDate::update_time();
}
/**
* Implements hook_ENTITY_TYPE_update().
*/
function manage_finish_date_node_update(Node $node) {
ManageFinishDate::update_time();
}
You should also have another file called 'src/ManageFinishDate.php' that should look like this:
<?php
namespace Drupal\manage_finish_date;
use Drupal;
use Drupal\node\Entity\Node;
class ManageFinishDate {
public static function update_time($node, $action = 'create') {
// Entity bundles to act on
$bundles = array('to_do_item');
if (in_array($node->bundle(), $bundles)) {
// Load the node and update
$status = $node->field_status->value;
$node_to_update = Node::load($node);
if ($status == 'completed') {
$request_time = Drupal::time();
$node_to_update->set('field_date_finished', $request_time);
$node_to_update->save();
}
}
}
}
The code is untested, but should work. Make sure that the module name, and namespace match as well as the class filename and class name match for it to work. Also, clear you cache once uploaded.
This will handle newly created and updated nodes alike.
Please look after this sample code which may help you:
function YOUR_MODULE_entity_presave(Drupal\Core\Entity\EntityInterface $entity) {
switch ($entity->bundle()) {
//Replace CONTENT_TYPE with your actual content type
case 'CONTENT_TYPE':
$node = \Drupal::routeMatch()->getParameter('node');
if ($node instanceof \Drupal\node\NodeInterface) {
// Set the current date
}
break;
}
}

Trying to find a file that doesnt exist Yii2

Im trying to create an email function that sends a file attached.
I've created the function and added attach() with the route of file I want to attach as follows:
public function newMonthlyBillingRegister(Clinic $clinic, ClinicMonthlyBilling $clinicMonthlyBilling)
{
$countryAdmins = $clinic->findCountryAdmins($clinic->country->id);
$adminEmails = [];
foreach ($countryAdmins as $admin) {
$adminEmails[$admin->email] = $admin->fullName;
}
/** #var BaseMailer $mailer */
$mailer = Yii::$app->mailer;
$mailer->htmlLayout = 'layouts/standard_html';
//$mailer->htmlLayout = 'layouts/invoice_html';
// $mailer->textLayout = 'layouts/invoice_text';
try{
return $mailer
->compose(
['html' => 'newMonthlyBillingRegister-html', 'text' => 'newMonthlyBillingRegister-text'],
[
'clinic' => $clinic,
'clinicMonthlyBilling' => $clinicMonthlyBilling,
]
)
->setFrom([Yii::$app->params['supportEmail'] => Yii::t('app', 'support-email-name', ['appName' => Yii::$app->name])])
->setTo($adminEmails)
->setSubject(Yii::t('app', '[CLINIC][BACKOFFICE] A clinic has upgraded its information in Guarantee Fund Modal.'))
->attach('app/media/uploads/clinic/monthly-billing/'.$clinicMonthlyBilling->trimestralBillingFile)
->queue() && YII_DEBUG && Yii::$app->mailqueue->process();
}
catch(\Exception $e){
LogService::getLogger()->error("Error while sending mail.","EmailService:newMonthlyBillingRegister()",$e->getMessage());
}
}
It gave me an error, but the problem comes when I delete attach() from my code, reverting all my changes on this email function, and when I try to send again the email the following message appears:
PHP Warning: fopen(app/media/uploads/clinic/monthly-billing/user_1_clinic_1_trimestral_billing_file_2019_05_09_08_22_35): failed to open stream: No such file or directory in /app/vendor/swiftmailer/swiftmailer/lib/classes/Swift/ByteStream/FileByteStream.php on line 142
The user_1_clinic_1_trimestral_billing_file_2019_05_09_08_22_35 file doesnt exist in app/media/uploads/clinic/monthly-billing/ folder and even in my database
...what's wrong?¿ I know is in my local but I dont know the reason of trying to search a file that doesn't exist and I didn't code anything to search it,
Anyone can help? Im using PHPStorm,
Thanks a lot for your attention!
I had to clean my email queue and it worked!! Thanks a lot Insane Skull for your help ;)

[Zend_Form][1.11.1] Error Message Fatal error: Class 'Admin_Form_Login' not found in ...\modules\default\controllers\IndexController.php

I don't speak english fluently (i'm french) so i will be
i followed the tutorial here and i got this structure
Application
--Modules
------admin
---------controller
---------views
------etat
---------controller
---------views
------default
---------controller
---------views
--configs
bootstrap.php
My problem is that, when i created my first form and tried to view it in my browser, i got the following error:
Fatal error: Class 'Admin_Form_Login' not found in C:\wamp\www\get\application\modules\default\controllers\IndexController.php on line 14.
Here is my code:
My controller : /modules/etat/controller/IndexController.php
class Etat_IndexController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
// action body
$form = new Etat_Form_InfoAgent();
$this->view->form = $form;
}
}
My form : /modules/etat/forms/InfoAgent.php
class Etat_Form_InfoAgent extends Zend_Form
{
public function init()
{
/* Form Elements & Other Definitions Here ... */
$this->setName('infoagent');
$this->setMethod('post');
$login = new Zend_Form_Element_Text('matricule');
$login->setLabel('Matricule:');
$login->setRequired(true);
$login->addFilter('StripTags');
$login->addFilter('StringTrim');
$this->addElement($login);
$password = new Zend_Form_Element_Password('agence');
$password->setLabel('Code agence:');
$password->setRequired(true);
$password->addFilter('StripTags');
$password->addFilter('StringTrim');
$this->addElement($password);
$submit = new Zend_Form_Element_Submit('submit');
$submit->setLabel('Valider');
//$submit->style = array('float: right');
$this->addElement($submit);
}
}
My view : /modules/etat/view/script/index.phtml
<br /><br />
<div id="view-content">
<?php echo $this->form; ?>
</div>
Configuration file : configs/application.ini
[production]
phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
includePaths.library = APPLICATION_PATH "/../library"
bootstrap.path = APPLICATION_PATH "/Bootstrap.php"
bootstrap.class = "Bootstrap"
appnamespace = "Application"
resources.frontController.controllerDirectory = APPLICATION_PATH "/controllers"
resources.frontController.params.displayExceptions = 0
;Modular structure
resources.modules[] =
resources.frontController.moduleDirectory = APPLICATION_PATH "/modules"
resources.frontController.params.prefixDefaultModule = "1"
;database ressources
resources.db.adapter = PDO_MYSQL
resources.db.params.host = localhost
resources.db.params.username = root
resources.db.params.password =
resources.db.params.dbname = bd_test
[staging : production]
[testing : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
[development : production]
phpSettings.display_startup_errors = 1
phpSettings.display_errors = 1
resources.frontController.params.displayExceptions = 1
I have searched the web for solution but i didn't get it. I saw a post about the same problem on your website (stackoverflow) and i tried to aplly your instructions without solving my problem.
i precise that i haven't change the code on my bootstrap and my public/index.php file
I hope you could help me soon.
thx
Make sure you have created a Bootstrap.php in each module directory, which looks like:
class Admin_Bootstrap extends Zend_Application_Module_Bootstrap
{}
In which Admin is the name of the module.
Also, make sure there is actually a file Login.php inside directory modules/admin/forms with a class Admin_Form_Login