jeudi 31 mai 2018

laravel how to store 2 array into same row on DB

I working on laravel 5.1. I was stuck on figuring how to store my 2 arrays input into the same row on DB. I only know how to store for one array.

$amount[] = $request->amount;
$receipt[] = $request->receipt;

foreach ($amount as $key => $value) {
  $reimbursement_item = ReimbursementItem::create([
     'user_id' => $user->id,
   'amount' => $value,
  ]);
}

DB structure and aspect result:
id  user_id  amount  receipt
--  -------  ------  --------------
1    32      40.00   /images/r1.jpg
2    24      60.00   /images/r2.jpg



via Chebli Mohamed

mardi 29 mai 2018

I'm facing the issue mentioned below while displaying the price list for the domains suggested

While getting tld's and domain name from enom api I'm getting error as "Unsupported Operand" for particular tld's like "co.in","in.net". Suggest me a solution to solve this.

Find below my controller code

   public function domaincheck(Request $request)
  {
        $sld = $request['sld'];
        $tld = $request['tld'];
        $response = file_get_contents('https://reseller.enom.com/interface.asp?command=check&sld='. $sld .'&tld='. $tld .'&uid=decksys&pw=Amy.th3ist4917&responsetype=xml');  
        $data = simplexml_load_string($response);
        $configdata   = json_encode($data);
        $final_data = json_decode($configdata,true);// Use true to get data in array rather than object
        // dd($final_data);
 }

The blade code is given below:

     <div class="form-group">
     <div class=" col-lg-2"></div>
     <div class="col-lg-8">
         <div class="input-group m-b">
            <span class="input-group-addon" style="padding-left:10px; background-color: #999;" class='unclickable'>www</span>
            <input type="text" name="sld" class="form-control" required>
  <span class="input-group-addon">

  <select class="form-control" name="tld" style="width: 100px;">
  <option value="com">com</option>
  <option value="in">in</option>
  <option value="info">info</option>
  <option value="org">org</option>
  <option value="co.in">co.in</option>
  <option value="in.net">in.net</option>
  <option value="net">net</option>
  <option value="biz">biz</option>
      </select>  
      </span>
      <span class="input-group-addon">
      <button type="submit" class="btn btn-sm btn-success" >Submit</button>  
      </span>

My route is given below:

Route::get('/registerdomain','EnomController@domaincheck');



via Chebli Mohamed

jeudi 24 mai 2018

Laravel 5.1 random timeout in ExcludeDirectoryFilterIterator

I'm seeing quite a few timeout errors on a big laravel 5.1 site:

[2018-05-23 17:02:35] production.ERROR: exception 'Symfony\Component\Debug\Exception\FatalErrorException' with message 'Maximum execution time of 30 seconds exceeded' in /var/www/vhosts/{site}/httpdocs/bootstrap/cache/compiled.php:16501 Stack trace: 0 {main}

Looking into the compiled.php file on that line number leads me to: ExcludeDirectoryFilterIterator@hasChildren

This function is from symfony/finder (version v2.7.47) https://github.com/symfony/finder/blob/34226a3aa279f1e356ad56181b91acfdc9a2525c/Iterator/ExcludeDirectoryFilterIterator.php#L73

I've used debug_backtrace on this function to see what's calling it and it looks to be laravel when loading the configuration from storage (local disk).

Does anybody know of any issue with this? Is the server disk getting hit hard at some times during the day causing loading the config to timeout?

Any help/suggestions much appreciated.



via Chebli Mohamed

lundi 21 mai 2018

404 NOT FOUND when use locales

I am using middlleware to switch between languages English an Arabic

<?php

namespace App\Http\Middleware;

use Closure;

class ApplyLocale
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $segments = collect($request->segments());

        $locale = $segments->first();

        if (! in_array($locale, config('app.locales'))) {
            $locale = 'ar';
            app()->setLocale($locale);
            $segments->prepend($locale);

            return redirect($segments->implode('/'));
        }

        app()->setLocale($locale);

        return $next($request);
    }
}

and in helper.php I use this to switch between

/**
 * @return string
 */
function switchLocaleUrl()
{
    $locale = config('app.locale');

    if ($locale === 'ar') {
        return '/en/' . collect(Request::segments())->splice(1)->implode('/');
    }
    return '/ar/' . collect(Request::segments())->splice(1)->implode('/');
}

and in view I use :

  <li><a href=""><i class="hvr-float-shadow"></i> </a></li> 

but when I go to url localhost/myproject/ar the error 404 NOT FOUND happened



via Chebli Mohamed

samedi 19 mai 2018

I got the json data from the url and I need to print the json data in my laravel 5.6 view

Trying to print the json data in my laravel5.6 view using controller. I got an error Illegal string offset 'rates'

My Controller Code

 $req_url = 'https://v3.exchangerate-api.com/bulk/6eea6e74c3abe1df9de390c2/USD';
 $response_json = file_get_contents($req_url);
 $configdata4   = json_encode($response_json);
 $final_data4 = json_decode($configdata4,true);
 return view('clientlayout.main.registerdomain',compact('final_data4'));

My view page Code

@foreach($final_data4['rates'] as $value)

@endforeach

Please suggest any solutions to this issue.



via Chebli Mohamed

jeudi 17 mai 2018

Laravel permission folder - I cant upload image into public/images

I have a folder images into public folder and when I try to write an image into that folder I got error:

FileException in File.php line 113: Unable to write in the "/home/USERNAME/public_html/public/images/Custaccounts/1102" directory

My all folders is with 755 permissions

enter image description here

How I can solve my problem? Why there is "Unable to write" error ?



via Chebli Mohamed

How to display a table in a popup box?

I have the form below, with 4 comboboxes "Metier=profession" "tache=task" "tacrification=pricing" et "technicien=technician", i select a Metier and a tache, after this i want that a popup box appears and show me a table that contains all the "techniciens" and their "tarification" (of course only the "techniciens" that are related with the "tache" already selected.) please see the second form.After this i select a "technician" from that table a now the form is completely filled with the "technician" and it's "pricing". Could anyone help me with this please?

enter image description here

what i'm trying to do enter image description here

intervention

    Schema::create('interventions', function (Blueprint $table) {
        $table->increments('id');
        $table->date('date_intervention')->nullable();
        $table->string('description');
        $table->dateTime('duree_prevu');
        $table->boolean('statut');
        $table->integer('technicien_id')->unsigned();
        $table->foreign('technicien_id')->references('id')- 
        >on('techniciens');
        $table->integer('tarification_id')->unsigned();
        $table->foreign('tarification_id')->references('id')- 
        >on('tarificationtaches');
        $table->integer('client_id')->unsigned();
        $table->foreign('client_id')->references('id')->on('Clients');


        $table->timestamps();
    });

tarificationtache

Schema::create('tarificationtaches', function (Blueprint $table) {
         $table->increments('id');
         $table->float('tarif', 8,2);
         $table->integer('tache_id')->unsigned();
         $table->foreign('tache_id')->references('id')->on('taches');
         $table->datetime('deleted_at')->nullable();
         $table->timestamps();
          });

Intervention extends Model

class Intervention extends Model
{
protected $fillable = [ ];
protected $guarded = [];

public function avisintervention()
{
    return $this->hasMany(AvisIntervention::class);
}

public function technicien()
{
    return $this->belongsTo(technicien::class);

}

public function client()
{
    return $this->belongsTo(Client::class);

}
 public function tarificationtache()
{
return $this->belongsTo('App\Tarificationtache','tarification_id');

}

class tache extends Model

class tache extends Model
{
use SoftDeletes;
protected $guarded = [];
 protected $dates = ['deleted_at'];

public function metier()
{
    return $this->belongsTo(Metier::class);
}

public function tarificationtache()
{
    return $this->hasMany(Tarificationtache::class);
}

}

class metier extends Model

class metier extends Model 
{
use SoftDeletes;
protected $guarded = [];
 protected $dates = ['deleted_at'];
public function taches()
{
    return $this->hasMany(Tache::class);
}
public function techniciens()
{
    return $this- 
    >belongsToMany('App\technicien','technicien_zone','metier_id','technicien_id');

}
}

class tarificationtache extends Model

class tarificationtache extends Model
{
use SoftDeletes;
protected $guarded = [];
 protected $dates = ['deleted_at'];
public function tache()
{
    return $this->belongsTo(Tache::class);
}


public function techniciens()
{
    return $this->belongsToMany('App\technicien','technicien_tarificationtache','tarificationtache_id','technicien_id');

}
public function intervention() {
    return $this->hasMany(intervention::class);
}

}

intervention controller

public function create()

{
    $client = client::orderBy('id', 'asc')->get();
    $metiers = metier::orderBy('id', 'asc')->get();
    $technicien = Technicien::orderBy('id', 'desc')->get();
    $tarifications = tarificationtache::orderBy('id', 'desc')->get();

    return view('intervention.create')->with('technicien', 
$technicien)->with('client',$client)->with('metiers',$metiers)- 
>with('tarifications',$tarifications);
}

/**
 * Store a newly created resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @return \Illuminate\Http\Response
 */
public function store(InterventionRequest $request)
{
    $intervention = new Intervention();

    $intervention ->description =$request->input('description');
    $intervention ->duree_prevu =$request->input('duree_prevu');


    if($request->has('statut')){
    $intervention->statut = $request->input('statut');
    }else{
           $intervention->statut = 0;
    }

    $intervention ->technicien_id = $request->input('technicien_id');
    $intervention ->client_id = $request->input('client_id');
    $intervention ->tarification_id = $request->tarificationtache_id;
    $intervention->save();
    return redirect('intervention');

    }



via Chebli Mohamed