jeudi 6 juillet 2017

Autofill / Autocomplete using Larave 5.1 / php backend

I want to auto-submit a third party multi-step form using php on the back end and possibly crawl a couple of pages after submission. A good example would be log into an e-commerce site on a user's behalf and look get their purchase history. Or fill out a multi-page college application and get the submission confirmation page along with the application id. Any suggestions?



via Chebli Mohamed

mercredi 5 juillet 2017

Node js file upload empty request in lumen

When i upload a file in Node JS, ajax request send to Lumen. But the request is empty.

This happen only on server, In my localhost working fine.

Please advice..

Ajax request :

uri: config.apiEndpoints.uploadStatement,
headers: {
    'Authorization': token
},
method: 'POST',
formData: {
    lender: "lender",
    product: "product",
    source: "statement",
    "document[]": formData[1].statement ? fs.createReadStream(formData[1].statement[0].path) : "",
    "document_key[]": formData[0].password[0],
} 

Lumen :

public function uploadstatement(Request $request)
{
  \Log::info(json_encode($request->all()));
  
  $basicRules = [
      'lender' => 'required|in:'.implode(',', config('api.lenderList')),
      'source' => 'required|in:'.implode(',',  config('api.sources'))
  ];
  $validator =  Validator::make($request->all(), $basicRules, [
      'lender.in' => 'Requested lender doesn\'t exist in our list',
      'source.in' => 'Requested source doesn\'t exist in our list'
  ]);
  if ($validator->fails()) {            
      return $this->showValidationResponse($validator->messages());
  }
}


via Chebli Mohamed

mardi 4 juillet 2017

QueryGrammar is null in Laravel5.1/Jessenger 3.0 and MongoDB 3.4

I have a Laravel 5.1 application running on Ubuntu 16.04 and PHP 5.6

This was previously using mongo.so (the older MongoDB PHP driver) and I have migrated it to the new driver mongodb.so - this was required since I upgraded MongoDB to 3.4 and would like to connect to a MongoDB Replica Set

I was using Jennseger's library to connect, which I also upgraded - and updated the to the laravelcollective/html library as well

The current composer.json file looks like this:

..
"php": ">=5.5.9",
"laravel/framework": "5.1.*",
"laravelcollective/html": "5.1.*",
"jenssegers/mongodb": "3.0.*",
..

When I login to the application, it generates the following error:

in Builder.php line 214
at HandleExceptions->handleError('4096', 'Argument 2 passed to Illuminate\Database\Query\Builder::__construct() 
must be an instance of Illuminate\Database\Query\Grammars\Grammar, null given, called in 
<app_root>/vendor/laravel/framework/src/Illuminate/Database/Eloquent/Model.php on line 1873 and defined', 
'<app_root>/vendor/laravel/framework/src/Illuminate/Database/Query/Builder.php', '214', array('connection' => object(Connection))) in Builder.php line 214

I have followed the guidelines to a similar error and replaced my Eloquent models

e.g. the following:

use Jenssegers\Mongodb\Model;

class Alert extends Model
{
.. 
..
}

is replaced by:

use Jenssegers\Mongodb\Eloquent\Model as Eloquent;

class Alert extends Eloquent {
..
..
}

and the User model is now:

use App\Scopes\Traits\ReportingTrait;
 use Illuminate\Auth\Authenticatable;
 use Illuminate\Auth\Passwords\CanResetPassword;
 use Illuminate\Contracts\Auth\Authenticatable as AuthenticatableContract;
 use Illuminate\Contracts\Auth\CanResetPassword as CanResetPasswordContract;
 use Bican\Roles\Traits\HasRoleAndPermission;
 use Bican\Roles\Contracts\HasRoleAndPermission as HasRoleAndPermissionContract;

use Jenssegers\Mongodb\Eloquent\Model as Eloquent;

class User extends Eloquent implements AuthenticatableContract, CanResetPasswordContract, HasRoleAndPermissionContract
 {
     use Authenticatable, CanResetPassword, HasRoleAndPermission, ReportingTrait;
..
..
}

There is a readme from a previous version for the jennsegers library here

I seem to have the requirements checked - including:

> php -i | grep 'Mongo'
MongoDB support => enabled
MongoDB extension version => 1.2.9
MongoDB extension stability => stable



via Chebli Mohamed

lundi 3 juillet 2017

Laravel Mail send even if cc and bcc is null

I have mail send function in laravel

public static function Compose($to,$cc,$bcc,$subject,$body)
    {

        // return $to;
        try
        {
            $data = [
                'body' => $body
            ];

            if(env('APP_ENV') == "local") 
            {
                $email["subject"] = $subject;
                $email["to"] = $to;
                $email["cc"] = $cc;
                $email["bcc"] = $bcc;
                Mail::send('email.composeMail', $data, function ($message) use ($email) {

                    $message
                        ->subject($email["subject"])
                        ->to($email["to"]);
                        ->cc($email["cc"]);
                        ->bcc($email["bcc"]);
                });
            }
            else
            {
                $email["subject"] = $subject;
                $email["to"] = $to;
                $email["cc"] = $cc;
                $email["bcc"] = $bcc;

                Mail::send('email.composeMail', $data, function ($message) use ($email) {

                    $message
                        ->subject($email["subject"])
                        ->to($email["to"]);
                        ->cc($email["cc"]);
                        ->bcc($email["bcc"]);
                });
            }
        } 
        catch (\Exception $e) 
        {
            Log::critical('Critical error occurred upon processing the transaction in Email.php -> Email class -> RevertPropertyToInbox method');
            throw new CustomErrorHandler($e->getMessage(),Constant::LogLevelCritical);
        }
    }

In many cases CC and BCC is Null. But mails aren't sent and I am getting error message

enter image description here

Here , I want to use code as it is without checking if CC or BCC is null, Is there any thing missed by me so that I can achieve what I am planning to .



via Chebli Mohamed

Laravel checkbox implementation for updating database

I've been trying to make an attendance management system in Laravel. In the attendance view,when a checkbox is checked ,the controller function is supposed to increment the appropriate database column.

I've been having some issues.Here's my code: views:

<div class="container">
<!--<div class="row">-->
    <div class="col-md-8 col-md-offset-2">
       <div class="panel panel-default">

            <div class="panel-heading">Take Attendance</div>
            <h4><center>Teacher: </center></h4>
            <div class="form-inline">

             @foreach ($second as $sec)
                            <br>
                          <div class = "form-group">

                            
                            &nbsp&nbsp&nbsp&nbsp
                            
                            </div>
                            <div class = "form-group">
                            <!---->
                            <input tabindex="1" type="checkbox" value=""  name=""  />
                            </div>
             @endforeach

             </div>
             <br>
            <form action ="report_generate&<?php echo $name ?>" method = "post" enctype = "multipart/form-data" >
            <!--<input type = "hidden" name = "_token" value = "}"/>-->
             <div class = "form-group">
             <input type="submit" value= "Submit">
            <center><a href ="/home/report&<?php echo $name ?>">Report</a></center>
             </div>
            </form>

            </div>
    </div>
</div>

@endsection

Controller(for submit button):

public function report_generate($tabu)

{

$year = DB::table('sub')->select('Year')-
>where('sub.Subject_Name','=',$tabu)->get();

$sub_id = DB::table('sub')->select('Subject_Id')-
>where('sub.Subject_Name','=',$tabu)->get();

            ob_start();
            echo $year;
            $output=ob_get_contents();
            ob_end_clean();

            if ( $output=='[{"Year":1}]')
            {

                    $req = "first";
            }
            elseif ( $output=='[{"Year":2}]')
            {

                    $req = "second";
            }
            elseif ( $output=='[{"Year":3}]')
            {

                    $req = "third";
            }
            elseif ( $output=='[{"Year":4}]')
            {

                    $req = "fourth";
            }

            $final = DB::table($req)->get();
            //dd($final);
            //$columns = Schema::getColumnListing($req);
            //dd($sub_id);
            ob_start();
            echo $sub_id;
            //dd($sub_id);
            $va=ob_get_clean();
            $va = stripslashes($va);
            $txt = rtrim($va,"}]");
            $txt = ltrim($txt,"[{Subject_Id:");
            $txt = ltrim($txt,"Subject_Id:");
            $txt = explode(":",$txt);
            $txt = str_replace('"','', $txt);
            //dd($txt[1]);

            $columns = Schema::getColumnListing($req);
            //dd($columns);
            //dd($txt);
            foreach ($columns as $col)
            {
                    //dd("Y");
                    if($col == $txt[1])
                    {
                            $got=DB::table($req)->select($col)->get();
                            //dd($got);
                            foreach($got as $g)
                                    {

                                            //want to increment that cell value

                                    }
                    }
            }
    }



via Chebli Mohamed

dimanche 2 juillet 2017

laravel artisan migrate: when table already exist goes into memory loop

I am using laravel 5.1

when i try $ php artisan migrate:install first time

I have a mysql database "quickstart" with "migrations" table in it.

When i try second time:

$ php artisan migrate:install

(it just hangs)

so i tried

$ strace php artisan migrate:install

i found the following:

.
.
.
poll([{fd=5, events=POLLIN|POLLERR|POLLHUP}], 1, 1471228928) = 1 ([{fd=5, revents=POLLIN}])
recvfrom(5, "le 'migrations' already exists", 93, MSG_DONTWAIT, NULL, NULL) = 30
brk(0x2ee0000)                          = 0x2ee0000
mmap(NULL, 401408, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0x7fe96b647000
mremap(0x7fe96b647000, 401408, 405504, MREMAP_MAYMOVE) = 0x7fe96279d000
mremap(0x7fe96279d000, 405504, 409600, MREMAP_MAYMOVE) = 0x7fe96b645000
mremap(0x7fe96b645000, 409600, 413696, MREMAP_MAYMOVE) = 0x7fe96279b000
mremap(0x7fe96279b000, 413696, 417792, MREMAP_MAYMOVE) = 0x7fe96b643000
mremap(0x7fe96b643000, 417792, 421888, MREMAP_MAYMOVE) = 0x7fe962799000
mremap(0x7fe962799000, 421888, 425984, MREMAP_MAYMOVE) = 0x7fe96b641000
mremap(0x7fe96b641000, 425984, 430080, MREMAP_MAYMOVE) = 0x7fe962797000
mremap(0x7fe962797000, 430080, 434176, MREMAP_MAYMOVE) = 0x7fe96b63f000

.
.
.

Instead of going into some memory loop and hang why its not showing the message that the table already exists.



via Chebli Mohamed

samedi 1 juillet 2017

Update laravel 5.0 to 5.1 on a server with php below 7

I am running a laravel 5.0 app and I am planning to upgrade to 5.1 to gradually get to 5.4, I'm using an Arvixe server with SSH, CPanel and WHM access I know 5.1 needs PHP 5.6.30 to run and right now my application is running with PHP 7.0 but in order to do it I had to change in Cpanel the php selector to PHP 7 because by default PHP 5.4 was in place and now when I try to update my app is telling me that php version is below requirements I even try to install laravel 5.1 from 0 and I am getting the same error, is that and indication that my server has only PHP 5.4 and is so how I was able to change the PHP selector to 7?

what I can do to update my app?



via Chebli Mohamed