dimanche 27 octobre 2019

Delete products url not working in Laravel

I want a user to delete a product when he clicks unlike button but I'm getting an error 404 url not found, but I have the url.

If I put dd($product) before $like = Like::findOrFail($product); it displays the id(4) but if I put dd($like), then it throws an error 404. How can I make this function work?.

Controller

 public function destroy($product)
 {
   $like = Like::findOrFail($product);
     dd($like);
   $like->delete();

  return 'done';
 }

Blade

  <a class="remove"  href="" > Unlike </a>

Route

 Route::get('product/{product}/unlike', ['as' => 'product.unlike', 'uses' => 'LikeController@destroy']);


via Chebli Mohamed

How to update mdf version?

I want to update my mpf version in xampp.

How it is possible?

I need mPDF v7.1.7 version.

composer require mpdf/mpdf This command is not working. Giving error!!

[Composer\Downloader\TransportException] The "https://api.github.com/repos/hillelcoren/omnipay-wepay" file could not be downloaded: failed to open stream: A connection attempt failed because the connected party did not properly respond after a period of time, or establis hed connection failed because connected host has failed to respond.



via Chebli Mohamed

Displaying liked products from database laravel

I want to display all liked products of a specific user from the database, but I'm getting an error Integrity constraint violation: 1052 Column 'deleted_at' in where clause is ambiguous .How can I display all liked products of specific user?

Like.php

class Like extends Model
{
use SoftDeletes;

protected $table = 'likeables';

protected $fillable = [
    'user_id',
    'likeable_id',
    'likeable_type',
];

/**
 * Get all of the products that are assigned this like.
 */
public function products()
{
    return $this->morphedByMany('App\Product', 'likeable');
}

}

Product.php

   public function likes()
{
    return $this->morphToMany('App\User', 'likeable')->whereDeletedAt(null);
}

public function getIsLikedAttribute()
{
    $like = $this->likes()->whereUserId(Auth::id())->first();
    return (!is_null($like)) ? true : false;
}

User.php

public function likedProducts()
{
return $this->morphedByMany('App\Product', 'likeable')->whereDeletedAt(null);
}

Blade file

@foreach (Auth::user()->likedProducts as $product)

<h2></h2>

@endforeach


via Chebli Mohamed

many to many relationship error in laravel

i have two tables,

1) qualifs

2) teachers

one teacher can have many qualifications

i created

pivot table; qualif_teacher

with two columns (teacher_id & qualif_id)

when i am saving teacher info, teachers qualifications are saving correctly with multiple ids, my problem is i am getting error when i try to view any teachers qualification in my blade file.

error: Undefined variable: teacher

Route: /teachers

Index Controller:

public function index()
{
  $teachers= DB::table('teachers')
  $qualifs = DB::table('qualifs')->find($teachers);
return view('teachers.index',compact('teachers','qualifs'));
}

Edit Controller:

public function edit($id)
  {
    $qualifs = DB::table('qualifs')->find($id);
      $teacher = Teacher::find($id);
      return response()->json([
          'status' => 'success',
          'teacher' => $teacher,
          'qualifs'=>$qualifs,
      ]);

  }

View:

@if(isset($teacher))
  @foreach($teacher->qualifs as $qualif)
      <li></li>
      @endforeach
@endif


via Chebli Mohamed

How to take value of 2nd array of matching key of first array

I have 2 arrays: Mapped Data:

Array
(
    [0] => Array
        (
            [id] => 
        )

    [1] => Array
        (
            [country_code] => 
        )

    [2] => Array
        (
            [user_id] => 
        )

    [3] => Array
        (
            [category_id] => 
        )

    [4] => Array
        (
            [post_type_id] => 
        )

    [5] => Array
        (
            [make] => make
        )

    [6] => Array
        (
            [description] => description
        )
}

Now I have another array which is my CSV Data:

Array
(
    [0] => Array
        (
            [status] => used
            [type] => Trailer
            [category] => Storage
            [location] => Calgary AB
            [make] => Strick
            [model] => Storage Van
            [year] => 1997
            [last_update] => 8/30/2019
            [unit_number] => VE420900U
            [vin] => 1S11E8283VE420900
            [price] => 2900
            [currency] => C
            [body_style] => Storage
            [colour] => Grey
            [suspension] => Spring Ride
            [suspension_type] => 
            [axle_config] => Single
            [trailer_length] => 28
            [width] => 0
            [height] => 0
            [description] => Storage,  suspension, Single axle, Steel rims, Wood floor, Roll up rear door rear door, Length: 28ft
            [main_photo] => https://www.maximinc.com/images/trailer/1997-strick-storage-van-40192.jpg
            [thumbnail] => https://www.maximinc.com/images/trailer/t-1997-strick-storage-van-40192.jpg
            [main_photo_date] => 10/18/2017 21:57
            [url] => View Online
        )

    [1] => Array
        (
            [status] => used
            [type] => Trailer
            [category] => Storage
            [location] => Calgary AB
            [make] => Roussy
            [model] => Storage Van
            [year] => 1987
            [last_update] => 8/30/2019
            [unit_number] => H1004175U
            [vin] => 2R183M3C1H1004175
            [price] => 4900
            [currency] => C
            [body_style] => Storage
            [colour] => White
            [suspension] => Spring Ride
            [suspension_type] => 
            [axle_config] => Tandem
            [trailer_length] => 48
            [width] => 102
            [height] => 0
            [description] => Storage,  suspension, Tandem axle, Steel rims, Wood floor, Swing rear door, Width: 102in, Length: 48ft
            [main_photo] => https://www.maximinc.com/images/trailer/1987-roussy-storage-van-40238.jpg
            [thumbnail] => https://www.maximinc.com/images/trailer/t-1987-roussy-storage-van-40238.jpg
            [main_photo_date] => 10/18/2017 22:07
            [url] => View Online
        )
)

Now I want to take CSV Arrays values if CSV arrays key is matching with Mapped Data Value.

I created logic and try array_key_exists but failed, I try this code of my logic but what it does it is inserting false entries into dbs

If matched I want an array final like

Array
( 
  [0]=> Array
     (
       [description] =>Storage,  suspension, Single axle, Steel rims, Wood floor, Roll up rear door rear door, Length: 28ft
       [make] => Strick
     )
  [1]=> Array
     (
       [description] =>Storage,  suspension, Tandem axle, Steel rims, Wood floor, Swing rear door, Width: 102in, Length: 48ft
       [make] => Roussy
     )
)

Here is my logic,

foreach ($json_decode as $key => $value) 
            {
                /*if(!empty($value))
                {
                    $jsonvalue = (array)$value;
                    foreach ($jsonvalue as $jkey=> $jvalue) 
                    {
                        foreach ($mapped_data as $mkey => $mvalue) 
                        {
                            $mvalue = (array)$mvalue;
                            foreach ($mvalue as $mappedkey=> $mappedvalue) 
                            {
                                if($jkey == $mappedvalue)
                                {
                                    if(!empty($jvalue))
                                    {
                                        // echo "Matched one====".'<br>';
                                        // print_r($jkey).'<br>';   
                                        // print_r($mappedvalue).'<br>';    
                                        // print_r($jvalue).'<br>';

                                        $post->$mappedvalue = $jvalue;
                                        $post->title = 'test';
                                        $post->category_id = '0';
                                        $post->city_id = '0';
                                        //$post->save();
                                    }   
                                }
                            }
                        }

                    }
                }

Where my $json_decode is my CSV Data array.

Can anyone help me out?



via Chebli Mohamed

samedi 26 octobre 2019

Query: product quantity with customizable variable like color, size

I want to make a report from stock_reports table where I want to show quantity of every product with variable like color, size based on created_at means every lot. i have used following Query but i needs some improvement.

$stockReport = DB::table('products')
        ->rightjoin('stock_reports','stock_reports.product_id','products.id')
         ->join('sizes','sizes.id','stock_reports.size_id')
         ->join('colors','colors.id','stock_reports.color_id')
        ->select('products.product_name','stock_reports.created_at'
            DB::raw('sum(quantity)'))

        ->groupby('stock_reports.created_at','products.product_name')
        ->orderby('stock_reports.created_at','desc')
        ->get();

Output should Like:

Name           Quantity    CREATED_AT
product_name1  XL-BLUE-15, L-RED-20 2019-08-12 
product_name2  L-BLUE-15, S-RED-20 2019-08-12
product_name1  M-BLUE-15, L-RED-20 2019-08-13

My table Structure:

products:

 id product_name

stock_reports

 id
 product_id
 size_id
 quantity
 color_id
 sold_price

sizes

  id
  size_name

colors

  id
  color_name


via Chebli Mohamed

jQuery Ajax JSON use Serialize() send data Form laravel

[process 1][1]

process[1]: https://i.stack.imgur.com/msjFq.png [process 2][2] process[2]: https://i.stack.imgur.com/uJfQh.png [process 3][3] process[3]: https://i.stack.imgur.com/42Ocs.png

process 1 click a popup will appear.
process 2 when clicking submit the select data to sead the information to another form.
process 3 the select data to display

help me please TT


via Chebli Mohamed