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