mercredi 26 décembre 2018

How i get image from database to view file in laravel

 <img  src=""  width="140" height="140">

this is the line which i use to get image from database to view file

i use bellow controller to get this image

public function show($id)
{

    $post=Clients::find($id);
    return view('pet.shw',['post'=>$post,'pets'=>$post->pets]); }

and also migration file is shown bellow

public function up()
{
    Schema::create('clients', function (Blueprint $table) {
        $table->increments('id');
        $table->string('ename');
        $table->string('mobile');
        $table->string('mail');
        $table->binary('image') ; //image that i wanna use 
        $table->mediumText('Discription');
        $table->timestamps();
    });
}

this approach was not worked view shows like this how can i solve this problem,suggest the new approaches better than that, i can't use public/storage folder because of all the images should be saved in database



via Chebli Mohamed

lundi 24 décembre 2018

Improving a model attribute for better efficiency and usability

Framework: Laravel 5.1

Background: I have a Product and a ProductVariation model, which both share a ImplementsProductAttributes trait. If a Product is variable, than the product should contain at least a single purchasable ProductVariation to be purchasable, rest of the logic would be obvious within the code sample from the trait. Functionality works as is.

public function getPurchasableAttribute()
{
    if ($this instanceof \App\Product)
    {
        if ($this->type == 'variable')
        {
            foreach ($this->variations as $variation)
            {
                if ($variation->purchasable)
                    return true;
            }

            return false;
        }
        else return $this->isItemPurchasable();
    }
    else
    {
        return $this->isItemPurchasable();
    }
}

public function isItemPurchasable()
{
    if($this->regular_price > 0 AND $this->published)
    {
        if ($this->manage_stock) 
        {
            return $this->stock_quantity > 0;
        }
        else return $this->in_stock;
    }
    else return false;
}

Pros:

  • I make use of laravels attributes,
  • Readable/maintainable code,

Cons:

  • Redundant eager loading on the variations (which could be a problem if this was supposed to be used on an API)
  • Redundant SQL queries (I could implement a single query to get a count in the end, and decide based on that if the product itself is purchasable, but instead I am loading all variations -- at least until i get one with purchasable=true --)

Question: Should I keep this implementation or should I improve by getting rid of pulling relationships and making a simple SQL query to get the purchasable variations?

Please elaborate on your answer as much as you can.

Edit: Also please let me know if you think any other pros/cons exist.



via Chebli Mohamed

dimanche 23 décembre 2018

SVN forbidden by the server issue

I am getting below error while I am committing in SVN.

foysal@laptop:~/Videos/osmall/trunk$ svn commit -m "fixed form submission"
Sending        app/Http/Controllers/DebitNoteController.php
Sending        app/Http/Controllers/SellerHelpController.php
Sending        config/database.php
Sending        resources/views/debitnote/debitnote_view.blade.php
Sending        resources/views/jaguar/jaguar.blade.php
Sending        resources/views/seller/debtor_ageing.blade.php
Sending        resources/views/seller/members.blade.php
Transmitting file data ...svn: E195023: Commit failed (details follow):
svn: E195023: Changing file '/home/foysal/Videos/osmall/trunk/config/database.php' is forbidden by the server
svn: E175013: Access to '/repos/osmall/!svn/txr/10920-90t/trunk/config/database.php' forbidden



via Chebli Mohamed

jeudi 20 décembre 2018

Got GLib-GObject-CRITICAL **: g_type_class_unref: assertion 'g_class != NULL' failed from laravel php controller

I have a file container encrypted via VeraCrypt in a USB flash drive, and I have a Web App based on the LAMP stack and under Laravel framework. Now, I want to mount the encrypted file via the laravel php controller like this:

$cmd = 'veracrypt -p "longlongpassword" /media/username/usbName/encryptedFile /media/veracrypt1'; $process = new Process($cmd); $process->run();

but got an error message says: "GLib-GObject-CRITICAL **: g_type_class_unref: assertion 'g_class != NULL' failed"

However, if I run the command

veracrypt -p "longlongpassword" /media/username/usbName/encryptedFile /media/veracrypt1

from Ubuntu terminal, then it is successfully done without any error.

Can anyone give some suggestion about how to solve this issue? Thanks.



via Chebli Mohamed

lundi 17 décembre 2018

Laravel Secuirty Audit Service

enter image description here

I am using Laravel framework 5.1 for my web application. I'm looking for an audit service where they can scan my current Laravel application for any security flaws before deployment to production environment.

How do I find those type of service online?

Can someone suggest something, please ?



via Chebli Mohamed

How to filter duplicated data of queried result?

 $users = UserDetails::select('user_details.user_id','user_details.user_nickname',
'user_media.media_url','sport_group_details.sport_group_name')
->join('users', function($join)
{
    $join->on('user_details.user_id', '=', 'users.id');

})->join('user_media',function($join){

    $join->on('user_details.user_id', '=', 'user_media.user_id');

})->join('user_to_sport_group_values',function($join){

    $join->on('user_media.user_id', '=', 'user_to_sport_group_values.user_id');

})->join('sport_group_details',function($join){

    $join->on('user_to_sport_group_values.sport_group_id', '=', 'sport_group_details.sport_group_id');

})
->selectRaw('( 6371 * acos( cos( radians(?) ) *
cos( radians( user_lat ) )
* cos( radians( user_lng ) - radians(?)
) + sin( radians(?) ) *
sin( radians(user_lat ) ) )
) AS distance', [$lattitude, $longitude, $lattitude])
->havingRaw("distance <= ?", [$max_distance])
->orderBy('distance')
->orderBy('user_details.user_nickname')->where('users.id','!=',$user_id)
->where('media_type','=','profile')
->where('sport_group_details.language_code','=', $country_code)
->get();

The User can have more than one sport_group_name So i want to get all the sport_group_name for indivisual user along with other data,But i am getting user duplicated multiples times , how can i filter that duplicated users, Any Help would be much appreciated , Thanks in advance.



via Chebli Mohamed

samedi 15 décembre 2018

Calling API of another laravel project

I have two laravel projects. One of them has an API

I am trying to get data using the API.

public function getSyncOrders() {
    $orders = Invoice::where('status', 0)->get();
    return response()->json([
        'data' => [
            'orders'                => $orders
        ]
    ], 200);      
}

I am trying to fetch data in the other laravel project.

public function syncOrders() {
    if(auth()->check()){
        Order::truncate();

        $curl = curl_init();

        curl_setopt_array($curl, array(
            CURLOPT_URL => "http://project1.net/api/sync-orders",
            CURLOPT_RETURNTRANSFER => true,
            CURLOPT_MAXREDIRS => 10,
            CURLOPT_TIMEOUT => 600,
            CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
            CURLOPT_CUSTOMREQUEST => "GET"
        ));

        $response = curl_exec($curl);
        $err = curl_error($curl);

        curl_close($curl);

        if ($err) {
            //echo "cURL Error #:" . $err;
        } else {
            echo $response;
        }
    }
    else{
        return redirect('/');
    }
}

But I get the error :

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'project2.invoice' doesn't exist (SQL: select * from invoice where status = 0)

Project 1 has table invoice in database while project 2 has table orders in database.

If I use the url http://project1.net/api/sync-orders in browser, it returns data.

I need help to fix the curl request so that project 2 doesn't execute code and search in its own database but instead get the data from the API.



via Chebli Mohamed

vendredi 14 décembre 2018

Laravel Call to a member function follows() on a non-object issue

My UserController includes the following:

public function doaction($domain, $some_id)
{
  $user = User::find(Sentry::getUser()->id);
  $user->doactions()->attach($some_id);
  $response = array('message' => 'doactioned', 'url' => 'http://'.$domain.'.'.Config::get('database.domain').'/undoaction/'.$some_id);
  return Response::json($response);
}

My routes.php includes also the following line:

Route::get('/{name}/doaction/{some_id}', array('as' => 'doaction', 'uses' => 'UserController@doaction'));

I am trying to call this front he frontend:

<a href="" class="tumblerclone-btn"> <i class="glyphicon glyphicon-plus"></i> Do action here </a>

And once its pressed (the URL is echoed properly), it leads me to an error:

Symfony \ Component \ Debug \ Exception \ FatalErrorException Call to a member function doactions() on a non-object

The highlighted code part of the error is:

public function doaction($domain, $some_id)
{
  $user = User::find(Sentry::getUser()->id);
  $user->doactions()->attach($some_id);
  $response = array('message' => 'doactioned', 'url' => 'http://'.$domain.'.'.Config::get('database.domain').'/undoaction/'.$some_id);
  return Response::json($response);
}

Any ideas are appreciated in advance.



via Chebli Mohamed

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