dimanche 29 avril 2018

php error with woocommerce Rest api

I am trying to add place order in woocommerce with rest api but showing me following error.

(1/1) HttpClientException cURL Error: Operation timed out after 15000 milliseconds with 0 bytes received.

language : php Framework : laravel

I tried increasing my local php script execution type but it is not working.



via Chebli Mohamed

Error when input date on laravel 5.4

i have using laravel to create prject. But i get some issue when creating a form that using date. Error unknown updated_at

Is there something missing in the table or script? Here the table Table

Here the controller

public function index(Request $request){
    $data = array();
    if($request->isMethod('post') == "post"){
        $pendaftar = new PendaftarModel();
        $pendaftar->tgl             =$request->input(['date']);
        $pendaftar->nopol           =$request->input('no polisi');
        $pendaftar->motor           =$request->input('jenis service');
        $pendaftar->servis          =$request->input('keluhan kendaraan');
        $pendaftar->keluhan         =$request->input('keluhan kendaraan');
        // $pendaftar->keluhan      =$request->input('keluhan kendaraan');

            if($pendaftar->save()){
                $data["status"]  = "success";
                $data["message"] = "Selamat, booking berhasil. Staff kami akan segera menghubungi anda untuk penjadwalan";
            }else {
                $data["status"]  = "danger";
                $data["message"] = "Maaf, Booking Gagal";
            }
    }
    return view("daftar", $data);

The view blade

div class="well well-lg">
    <div class="container">
        <h2>Booking Online</h2>
        <span>Halaman untuk melakukan pendaftaran kendaraan.</span>
    </div>
</div>

<div class="container">

    <div class="alert alert-info">
        <i class="glyphicon glyphicon-info-sign"></i> Silahkan isi data berikut
    </div>
    <div class="panel panel-primary">

        <div class="panel-heading">
            Form Data Kendaraan
        </div>
        <div class="panel-body">

            @if(isset($status))
            <div class="alert alert-<?php echo $status; ?>">
                <?php echo $message; ?>
            </div>
            @endif

            <form method="post">
                

            <div class="form-group">
                 <label for="tanggal">Pilih Tanggal</label>
                 <input class="form-control" id="tanggal" required type="date" name="tgl" max="3000-12-31" 
                        min="1000-01-01" placeholder="Pilih Tanggal">
            </div>

            <div class="form-group">
                <label for="nopol">Nomor Polisi:</label>
                <input class="form-control" id="nopol" required type="text" name="nopol" placeholder="Masukkan No Polisi">
            </div>

            <div class="form-group">
                <label for="motor">Jenis Motor:</label>
                <input class="form-control" id="motor" required type="text" name="motor" placeholder="Matic/Bebek/Sport">
            </div>

            <div class="form-group">
                <label for="servis">Tipe Service:</label>
                <input class="form-control" id="servis" required type="text" name="servis" placeholder="Besar/Kecils">
            </div>



            <div class="form-group">
                <label for="keluhan">Keluhan Kendaraan:</label>
                <textarea name="keluhan" id="keluhan" required class="form-control" rows="5" placeholder="Tulis Keluhan Motor Anda"></textarea>
            </div>

            <button type="submit" name="submit" class="btn btn-success btn-lg"><i class="glyphicon glyphicon-send"></i> Submit</button>
                <button type="reset" class="btn btn-danger btn-lg">Reset</button>
            </form>
        </div>
    </div>

</div>

The Model

{
//
protected $table = "pendaftar";
public $timestamps = true;
protected $fillable=['tgl','nopol','motor','servis','keluhan'];

}

Please help me to fix this, any comment will appreciate.

Bestly Regards



via Chebli Mohamed

Bootstrap modal form not submitted

I was trying to submit form which is inside a modal.The modal will come dynamically.

<a href="#" data-toggle="modal"  id="getProduct" data-url="" data-target="#modal-quickview">

Here is the Modal form which will store the data

{!! Form::open(['method' => 'POST','class'=>'contact_dialog','route' => 'storeCart', 'enctype'=>'multipart/form-data']) !!}
  {!! Form::token(); !!}
    @if($product->category_id == '1')
            <div class="product-color-size-area">
              <div class="color-area">
                <h2 class="saider-bar-title">Color</h2>
                <div class="color">
                  <select class="single-option-selector" name="color">
                    @foreach($colors as $color)
                      <option value=""></option>                    
                    @endforeach
                  </select>
                </div>
              </div>
              <div class="size-area">
                <h2 class="saider-bar-title">Size</h2>
                <div class="size">
                  <select class="single-option-selector" name="size">
                     @foreach($sizes as $size)
                      <option value=""></option>                     
                    @endforeach
                  </select>
                </div>
              </div>
            </div>
    @endif    

     @if($product->category_id == '3')
            <div class="product-color-size-area">
              <div class="size-area">
                <h2 class="saider-bar-title">Size</h2>
                <div class="size">
                  <select class="single-option-selector" name="frame_size">
                     @foreach($frame_sizes as $frame_size)
                      <option value=""></option>                     
                    @endforeach
                  </select>
                </div>
              </div>
            </div>
    @endif 

     @if($product->category_id == '4')
            <div class="product-color-size-area">
              <div class="size-area">
                <h2 class="saider-bar-title">Size</h2>
                <div class="size">
                  <select class="single-option-selector" name="shoe_size">
                     @foreach($shoe_sizes as $shoe_size)
                      <option value=""></option>                     
                    @endforeach
                  </select>
                </div>
              </div>
            </div>
    @endif   

    <input type="hidden" name="product_name" value="">       
            <div class="product-variation">

                <div class="cart-plus-minus">
                  <label for="qty">Quantity:</label>
                  <div class="numbers-row">
                    <div onClick="var result = document.getElementById('qty'); var qty = result.value; if( !isNaN( qty ) &amp;&amp; qty &gt; 0 ) result.value--;return false;" class="dec qtybutton"><i class="fa fa-minus">&nbsp;</i></div>
                    <input type="text" class="qty" title="Qty" value="1" maxlength="12" id="qty" name="quantity">
                    <div onClick="var result = document.getElementById('qty'); var qty = result.value; if( !isNaN( qty )) result.value++;return false;" class="inc qtybutton"><i class="fa fa-plus">&nbsp;</i></div>
                  </div>
                </div>
                <button  class="button pro-add-to-cart submitForm" title="Add to Cart" type="submit"><span><i class="fa fa-shopping-cart"></i> Add to Cart</span></button>             
            </div>
    {!! Form::close() !!}

The problem here is when i tried to submit the data it doesn't call the route means nothing happened. What could be possible reason for form not submitting?



via Chebli Mohamed

samedi 28 avril 2018

how to completely logout in laravel 5.5 controller?

After I logout of my laravel application, in the browser I press the button to backward (go back) and then I see the dashboard.

I want to eliminate this "session" that laravel mantein if I go back, (btw; when In that dashboard when I click other URL the middleware redirect me to the login view)

can anyone help me?

my route ->

Route::get('auth/logout', 'Auth\LoginController@logout')->name('logout');

my controller ->

<?php

namespace App\Http\Controllers;

use App\User;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Session;


class LoginController extends Controller
{
    private $user;


    public function logout(){
        Auth::logout();
        \Session::flash('success',"logout");
        return redirect()->route('login');
    }

}



via Chebli Mohamed

Model relationship creation uses the wrong field in Laravel

I want to create a new model using the relationship between a two model module and chapter and they have HasMany relationship between them as follow :

//Module mode
public function chapters()
{
    return $this->hasMany(Chapter::class, 'module_slug', 'slug');
}

//Chapters Model
public function module()
{
    return $this->belongsTo(Module::class, 'module_slug', 'slug');
}

And here's how I'm storing the models :

    $module = Module::create([
        'title' => $request->module_title,
        'icon' => $request->module_title
    ]);

    $module->chapters()->create([
        'pdf_url' => $path,
        'title' => $request->chapter_title
    ]);

The Issue :

The problem I got is that the $module->chapters()->create() is using the id not the slug which I'm specifying as the primary key like this :

//Module model
protected $primaryKey = 'slug';
protected $keyType = 'string';


//Chapters model
protected $primaryKey = 'slug';
protected $keyType = 'string';

I don't know why it uses the id field like this screenshot :

The issue



via Chebli Mohamed

How to Foreach loop through Laravel collection.?

i m a beginner at laravel. using 5.5 . i have this collection return by my controller :

$products = Product::with('bazar.resellers')->take(2)->get();
dd($products);
//return view('shop.index')->with('products', $products);

which basically is three tables with nested relations. Note the relations lists in the code below. i want to access data(all columns in red colour) from every model i have in the collection i.e. Product, bazar and reseller.

Relationships are quite fine. but how to retrieve it from a collection? i dunno how foreach loops play with a collection.

Collection {#578 ▼
#items: array:2 [▼
0 => Product {#487 ▼
  #fillable: array:7 [▶]
  #connection: "mysql"
  #table: null
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  #perPage: 15
  +exists: true
  +wasRecentlyCreated: false
  #attributes: array:10 [▼
    "id" => 1
    "created_at" => "2018-04-27 12:54:41"
    "updated_at" => "2018-04-27 12:54:41"
    "imgp" => "shirt.jpg"
    "title" => "shirt1"
    "Prod_descript" => "shirt1 is a good shirt"
    "price" => 10
    "reseller_id" => 1
    "City_id" => 1
    "bazar_id" => 1
  ]
  #original: array:10 [▶]
  #changes: []
  #casts: []
  #dates: []
  #dateFormat: null
  #appends: []
  #dispatchesEvents: []
  #observables: []
  #relations: array:1 [▼
    "bazar" => Bazar {#523 ▼
      #connection: "mysql"
      #table: null
      #primaryKey: "id"
      #keyType: "int"
      +incrementing: true
      #with: []
      #withCount: []
      #perPage: 15
      +exists: true
      +wasRecentlyCreated: false
      #attributes: array:7 [▼
        "id" => 1
        "Bazarname" => "Saddar"
        "Bazarlat" => null
        "Bazarlong" => null
        "created_at" => null
        "updated_at" => null
        "City_id" => 1
      ]
      #original: array:7 [▶]
      #changes: []
      #casts: []
      #dates: []
      #dateFormat: null
      #appends: []
      #dispatchesEvents: []
      #observables: []
      #relations: array:1 [▼
        "resellers" => Collection {#574 ▼
          #items: array:1 [▼
            0 => Reseller {#564 ▼
              #guard: "reseller"
              #fillable: array:12 [▶]
              #hidden: array:2 [▶]
              #connection: "mysql"
              #table: null
              #primaryKey: "id"
              #keyType: "int"
              +incrementing: true
              #with: []
              #withCount: []
              #perPage: 15
              +exists: true
              +wasRecentlyCreated: false
              #attributes: array:15 [▼
                "id" => 1
                "Fname" => "talha"
                "Lname" => "ali"
                "email" => "p@g.com"
                "password" => "$2y$10$M7wOmSouxSAYADN7NeFdSObT8fGwkEOFxVmOgcNSWvrixWCDtA/1S"
                "mobile_no" => "03169880008"
                "landline_no" => "0987654"
                "shop_name" => "MyTestSHop"
                "NIC_no" => "170178359437589754"
                "shop_address" => "University Town, Peshawar, Pakistan"
                "remember_token" => "wrb3nOwOWQcTuoF0P9KnaknwpOxfpTHt4gkShUmTzkR2Df9A7pPY5shBq6pQ"
                "created_at" => "2018-04-27 12:42:25"
                "updated_at" => "2018-04-27 12:42:25"
                "City_id" => 1
                "bazar_id" => 1
              ]
              #original: array:15 [▶]
              #changes: []
              #casts: []
              #dates: []
              #dateFormat: null
              #appends: []
              #dispatchesEvents: []
              #observables: []
              #relations: []
              #touches: []
              +timestamps: true
              #visible: []
              #guarded: array:1 [▶]
              #rememberTokenName: "remember_token"
            }
          ]
        }
      ]
      #touches: []
      +timestamps: true
      #hidden: []
      #visible: []
      #fillable: []
      #guarded: array:1 [▶]
    }
  ]
  #touches: []
  +timestamps: true
  #hidden: []
  #visible: []
  #guarded: array:1 [▼
    0 => "*"
  ]
}
1 => Product {#488 ▶}
]
}

the code i have tried is not working!

@foreach($products as $product)
<h1></h1>

@foreach($product->bazar as $bazar)
    <h3></h3>

    @foreach($bazar->resellers as $reseller)
        <p></p>
    @endforeach

@endforeach

@endforeach



via Chebli Mohamed

Auto close Alert bootstrap

Hi I´am using Laravel version 5.6 with Bootstrap 4 and I make an Alert message on the page. It already show, and close. But I can't make it auto close with the setTimeout function.

Thats the auto close code that doesn't work

enter image description here

Some one Knows what is happening?



via Chebli Mohamed