mardi 11 décembre 2018

Laravel 5.1 Intervention Image compressing

I use Laravel 5.1 and the intervention package: http://image.intervention.io/

I try to compress my images. I would like to upload a 2.5Mb image and compress it by reducing the image size to arround 700kb by keeping the resolution and the image quality. Just reducing a large image file to a small one. The uploaded image is a .jpg file

I use the following code:

$targetFolder = public_path().'/images/';
$name=$image->getClientOriginalName();
$extension = $image->getClientOriginalExtension(); // add
$picture = sha1($name . time()) . '.' . $extension; //add

$image->move($targetFolder, $picture);
$image = \Intervention\Image\Facades\Image::make(sprintf('images/%s', $picture))->encode('jpg', 75);

But my image size is still arround 2.07Mb

The question is what method I have to use to get the desired result?



via Chebli Mohamed

mewebstudio/captcha wrong captcha in validation

I know this topic is existing, but no one could solve my problem.
I am using the library mewebstudio/captcha, everything is fine, but when I submit, it tells me always that the captcha is wrong.

My validation rules:

'captcha' => 'required|captcha'

In my html form:

<?= captcha_img(); ?>
<input type="text" name="captcha">



I am using php5.6, Laravel 5.1 and mews/captcha 2.2



via Chebli Mohamed

vendredi 7 décembre 2018

Session expired randomly in laravel 5.1

session is being expired randomly after some pages requests. it is not fixed some time session expired between 10 to 15 minutes , some times session expired after 2 to 3 pages request only . And some times not every times when i posting data from a page it say's TokenMismatchException in VerifyCsrfToken.php but i've added in the form .

I'm using database driver for session. i would like to tell that before this i was using file driver for session but there was same condition.

here is my config/session.php file

``

return [

/*
|--------------------------------------------------------------------------
| Default Session Driver
|--------------------------------------------------------------------------
|
| This option controls the default session "driver" that will be used on
| requests. By default, we will use the lightweight native driver but
| you may specify any of the other wonderful drivers provided here.
|
| Supported: "file", "cookie", "database", "apc",
|            "memcached", "redis", "array"
|
*/

'driver' => env('SESSION_DRIVER', 'database'),

/*
|--------------------------------------------------------------------------
| Session Lifetime
|--------------------------------------------------------------------------
|
| Here you may specify the number of minutes that you wish the session
| to be allowed to remain idle before it expires. If you want them
| to immediately expire on the browser closing, set that option.
|
*/

'lifetime' => 120,

'expire_on_close' => false,

/*
|--------------------------------------------------------------------------
| Session Encryption
|--------------------------------------------------------------------------
|
| This option allows you to easily specify that all of your session data
| should be encrypted before it is stored. All encryption will be run
| automatically by Laravel and you can use the Session like normal.
|
*/

'encrypt' => false,

/*
|--------------------------------------------------------------------------
| Session File Location
|--------------------------------------------------------------------------
|
| When using the native session driver, we need a location where session
| files may be stored. A default has been set for you but a different
| location may be specified. This is only needed for file sessions.
|
*/

'files' => storage_path('framework/sessions'),

/*
|--------------------------------------------------------------------------
| Session Database Connection
|--------------------------------------------------------------------------
|
| When using the "database" or "redis" session drivers, you may specify a
| connection that should be used to manage these sessions. This should
| correspond to a connection in your database configuration options.
|
*/

'connection' => null,

/*
|--------------------------------------------------------------------------
| Session Database Table
|--------------------------------------------------------------------------
|
| When using the "database" session driver, you may specify the table we
| should use to manage the sessions. Of course, a sensible default is
| provided for you; however, you are free to change this as needed.
|
*/

'table' => 'sessions',

/*
|--------------------------------------------------------------------------
| Session Sweeping Lottery
|--------------------------------------------------------------------------
|
| Some session drivers must manually sweep their storage location to get
| rid of old sessions from storage. Here are the chances that it will
| happen on a given request. By default, the odds are 2 out of 100.
|
*/

'lottery' => [2, 100],

/*
|--------------------------------------------------------------------------
| Session Cookie Name
|--------------------------------------------------------------------------
|
| Here you may change the name of the cookie used to identify a session
| instance by ID. The name specified here will get used every time a
| new session cookie is created by the framework for every driver.
|
*/

'cookie' => 'laravel_session',

/*
|--------------------------------------------------------------------------
| Session Cookie Path
|--------------------------------------------------------------------------
|
| The session cookie path determines the path for which the cookie will
| be regarded as available. Typically, this will be the root path of
| your application but you are free to change this when necessary.
|
*/

'path' => '/',

/*
|--------------------------------------------------------------------------
| Session Cookie Domain
|--------------------------------------------------------------------------
|
| Here you may change the domain of the cookie used to identify a session
| in your application. This will determine which domains the cookie is
| available to in your application. A sensible default has been set.
|
*/

'domain' => null,

/*
|--------------------------------------------------------------------------
| HTTPS Only Cookies
|--------------------------------------------------------------------------
|
| By setting this option to true, session cookies will only be sent back
| to the server if the browser has a HTTPS connection. This will keep
| the cookie from being sent to you if it can not be done securely.
|
*/

'secure' => false,

]; ``



via Chebli Mohamed

mardi 4 décembre 2018

How to apply add Click event in laravel full calendar for particular event?

I am trying to apply click event on individual event once the user click on any event it should open a pop up or anything like that but i am not able to achieve this ,Any help would be much appreciated Thanks in advance, below is the code. `

@extends('layouts.app')
@include('layouts.navigations.profile')
@include('layouts.header')
@section('style')
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.2.7/fullcalendar.min.css"/>
@endsection
@section('content')
<div class="content-wrapper">
    <div class="container-fluid">
        <div class="row mt-4">
            <div class="col-md-12">
                <div class="card pd-card">
                    <div class="panel panel-default">
                        <div class="panel-heading"></div>
                        <div class="panel-body">
                            {!! $calendar->calendar() !!}
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

@section('script')
    <script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.9.0/moment.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/fullcalendar/2.2.7/fullcalendar.min.js"></script>
    {!! $calendar->script() !!}
@endsection
@section('script')
    <script>

    </script>
@endsection`



via Chebli Mohamed

lundi 3 décembre 2018

Undefined index: collation laravel 5.1 mysql connection

I m using laravel 5.1 to make connection to mysql host.Here is the sample.

\Config::set('database.connections.mysql', array(
        'driver' => 'mysql',
        'host' => "host name",
        'port' => 3306,
        'database' => 'db name',
        'username' => 'username',
        'password' => 'password'
    ));
$data = \DB::connection('mysql')
        ->table('tablename')
        ->get();

When i run the above code i get the error::

    [ErrorException]            
    Undefined index: collation 



via Chebli Mohamed

Laravel 5.1 Max image size

I'm using Laravel 5.1 and php 7. I try to implement an image upload. Large images fails to upload. (A white screen appears with no error message) I tested it locally on xampp and on a webspace. With small images it works. It fails with an image of 2.5MB but the max value is 5000.

My controller:

public function fileUpload(Request $request)

{

     $this->validate($request, [

        'image' => 'required|image|mimes:jpeg,png,jpg,gif,svg|max:5000',
     ]);


     $image = $request->file('image');

     $input['imagename'] = time().'.'.$image->getClientOriginalExtension();

     $destinationPath = public_path('/images');

     $image->move($destinationPath, $input['imagename']);


    $this->postImage->add($input);


    return back()->with('success','Image Upload successful');

}

The questions:

  1. Why there is no error message? Only a white screen appears when it fails to upload. (Maybe there is a necessary configuration to do in one of the laravel config files?
  2. Why it works with smaller images? Where in xampp and on the webspace it's a configuration necessary?


via Chebli Mohamed

dimanche 2 décembre 2018

How to send sms in laravel to all users if users table city matches with services table city?

I want to send sms to all users in laravel if service's table city field matches with user's city field.

Take a example:- if i submit a form for a service by selecting a city, then it will match with the users city field, if it matches then automatically send a sms to all users with same city..



via Chebli Mohamed