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

How does Remember me feature of Laravel works from core

I wanted to know how does Laravel (v5.1) authenticates the user by validating remember_me cookie on session expiration, I learned, how does this cookie is generated, but I'm unable to find how & where does Laravel validate this cookie, received from the request and re-generates the new session on expiration. I'm looking for code, that makes this mechanism work so that I can understand more clearly about How this mechanism actually works.



via Chebli Mohamed

mardi 15 mai 2018

How to track sessions & invalidate them on demand in Laravel 5.1

It started with invalidating all other sessions except current one when a user changes the password, so with this, I came with a thought, if I am doing this then why shouldn't the user be provided a facility/feature where a user can check a list of his active sessions and invalidate any of them whenever he/she wishes, thus a feature to track the user sessions...

Example: There are three sessions of the user, 1. Windows-Chrome, 2. Android-Chrome, 3. Mac-Safari. Now say user is currently logged in from 2nd one (Android-Chrome) and wishes to invalidate his 3rd session (Mac-Safari), then he should be able to do it. This feature, is what I am tring to achieve.

I'm working with Laravel 5.1 & file-driver based Sessions.

What I've done/tried:

  1. I created a separate sessions table for user (user_sessions) with following properties:

    id (PK), user_id(FK users table), session_id(varchar), ...userAgentProps fields..., created_at, updated_at

  2. Then overrode authenticated() & logout() methods within AuthController, to manage session records within user_sessions table. Whenever a user is authenticated, its session_id is recorded within the table, Whenever a user logs out, that session's record is removed from user_sessions table.

  3. Using user_sessions table, I can show a user the list of his active sessions. Now with this list, I'm providing a button saying invalidate this session which when clicked, would invalidate that particular session.

The Problem: Everything depicted above works just perfectly fine! but with a catch: User should not use remember me feature, Why?: Without remember me cookie, this works perfectly well, but with remember me cookie, browser re-logins the user, so deleting/invalidating the older session becomes of no use, as a fresh new session for the user is created using that remember me cookie within the browser.

The Question: How do I achieve this whole feature along with remember me cookie?



via Chebli Mohamed

lundi 14 mai 2018

How to display tld value from the json given below

From the below json I need to display the values of tld i.e., co.uk, eu, live, org...

Array ( [tldlist] => Array ( [tld] => Array ( [0] => Array ( [tld] => co.uk ) [1] => Array ( [tld] => eu ) [2] => Array ( [tld] => live ) [3] => Array ( [tld] => org ) [4] => Array ( [tld] => Array ( ) ) ) [tldcount] => 5 ) [Command] => GETTLDLIST [APIType] => API [Language] => eng [ErrCount] => 0 [ResponseCount] => 0 [MinPeriod] => Array ( ) [MaxPeriod] => 10 [Server] => SJL1VWRESELL_T [Site] => eNom [IsLockable] => Array ( ) [IsRealTimeTLD] => Array ( ) [TimeDifference] => +0.00 [ExecTime] => 0.000 [Done] => true [TrackingKey] => 7cbc3d47-c11c-4a39-8387-448777e82af5 [RequestDateTime] => 5/14/2018 12:21:18 AM [debug] => Array ( ) ) 1

find below my blade code:

 @foreach($final_data1['tldlist']['tld'] as $key)

    <br>

 @endforeach

Please suggest me corrections in my blade file to display the tld from the above json.



via Chebli Mohamed

dimanche 13 mai 2018

How to use session to be alive between http and https laravel 5.1

We recently bought an SSL from goDaddy domain and the site successfully used that SSL to amazon ec2. Though we will only use the https on a specific url like the billing (eg. https://www.ourdomain.com/billing) and the rest of the sites will still use the "HTTP"

My question is, is it possible for the session to be alive when switching to different protocol or http/https?

I found this link which should be the solution but when I tried adding the

'secure'    => true,
'http_only' => true,

it still didn't work.

Also when I tried logging-in using just the HTTP, i am unable to login. It seems the app is not functioning.

Sorry, this is my first time using SSL on a site. Any pointers is much appreciated.

Regards,



via Chebli Mohamed

vendredi 11 mai 2018

How to display a table in a popup box with javascript?

I have the form below, with 4 comboboxes "Metier" "tache" "tacrification" et "technicien", 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.) after this i select a "technicien" from that table a now the form is completely filled with the "technicien" and it's "tarification". Could anyone help me with this please?

enter image description here

iterventioncontroller

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 ->date_intervention =$request- 
>input('date_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->tarification_id;
$intervention->save();
return redirect('intervention');

}

create.blade.php

 @extends('Layouts/app')
 @extends('Layouts/master')

 @section('content')
 <!--  jQuery -->
 <script 

src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>



<script type="text/javascript">


var getTachesByMetierUrl = "";
var getAdresseByClientUrl = "";
var getTarificationsByTacheUrl = "";
var getTechniciensByTarificationtacheUrl = " 
";

//console.log(getMetiersByTechnicienUrl,getTachesByMetierUrl,getTarificationsByTacheUrl);

    function getAdresseByClient(val) {
    if(val.length>0) {
        var client_id = val;
        $.get(getAdresseByClientUrl+'/'+client_id,function(res) {
            var html = '<option value="">-Select-</option>' ;
            $.each(res.adresses,function(index,item) {
                html+='<option 
    value="'+item.id+'">'+item.code_postal+'</option>';
            });
            $('#adresses').html(html);

        });
    }
    }


function getTachesByMetier(val) {
    if(val.length>0) {
        var metier_id = val;
        $.get(getTachesByMetierUrl+'/'+metier_id,function(res) {
            var html = '<option value="">-Select-</option>' ;
            $.each(res.taches,function(index,item) {
                html+='<option 
  value="'+item.id+'">'+item.libelle_tache+'</option>';
            });
            $('#taches').html(html);

        });
    }
}
function getTarificationsByTache(val) {

    if(val.length>0) {
        var tache_id = val;
        $.get(getTarificationsByTacheUrl+'/'+tache_id,function(res) {
            var html = '<option value="">-Select-</option>' ;
            $.each(res.tarifications,function(index,item) {
                html+='<option 
  value="'+item.id+'">'+item.tarif+'</option>';
            });
            $('#tarifications').html(html);

        });
    }
}

function getTechniciensByTarificationtache(val) {
    if(val.length>0) {
        var tarificationtache_id = val;
        $.get(getTechniciensByTarificationtacheUrl+'/'+tarificationtache_id,function(res) {
            var html = '<option value="">-Select-</option>' ;
            $.each(res.techniciens,function(index,item) {
                html+='<option value="'+item.id+'">'+item.id+'</option>';
            });
            $('#techniciens').html(html);

        });
    }
}

@if(count($errors))
<div class="alert alert-danger" role="alert">
    <ul>
        @foreach($errors ->all() as $message)
            <li></li>
        @endforeach
    </ul>
</div>
@endif
<div class="container">
<div class="row"></div>
<div class="col-md-10">
    <h1>Ajout Intervention</h1>
    <form action=" " method="post">
        
        <div class="form-group">
            <label for="client">Client</label>
            <select onchange="getAdresseByClient(this.value)" 
 name="client_id" id="client" 
 class="form-control">
                <option value="">-Select-</option>
                @foreach($client as $t)
                    <option value="">
                        
                    </option>
                @endforeach
            </select>
        </div>


        <div class="form-group">
            <label for="">date intervention</label>

            <input class="form-control" type="date" id="example-date- 
 input" name 
 ="date_intervention" value="">
        </div>

        <div class="form-group">
            <label for="">description</label>
            <input type="text"  name ="description" class="form- 
 control"value=" 
 ">
        </div>


        <div class="form-group">
            <label for="">duree_prevu</label>
            <input class="form-control" type="datetime-local"  name 
 ="duree_prevu" value=" 
 ">
        </div>

 <div class="form-group">
            <div class="col-md-12">
            <div class="col-md-4">
            <label>Metier: </label>
            <select onchange="getTachesByMetier(this.value)" 
style="width: 200px" 
class="productm form-control" id="metiers">
           <option value="">-Select-</option>
                    @foreach($metiers as $t)
                    <option value="">
                        
                    </option>
                @endforeach
            </select>
        </div>

        <div class="col-md-4">
            <label>tache: </label>
            <select onchange="getTarificationsByTache(this.value)" 
style="width: 200px" 
class="productname form-control" name="tache" id="taches">
            <option value="">-Select-</option>
            </select>
        </div>

        <div class="col-md-4">
            <label>tarification: </label>
            <select 
 onchange="getTechniciensByTarificationtache(this.value)" 
 style="width: 
 200px" class="productname form-control" name="tarificationtache_id" 
 id="tarifications">
            <option value="">-Select-</option>
            </select>
        </div>

        <div class="col-md-4">
                    <label>technicien: </label>
                    <select style="width: 200px" class="productname 
 form-control" 
 name="technicien_id" id="techniciens">
                        <option value="">-Select-</option>
                    </select>
                </div>



 </div>
 </div>

 </div>
 </div>
 </div>

 <link 

href="https://ift.tt/1jAc5cP" rel="stylesheet">

<link href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap- 
datepicker/1.5.0/css/bootstrap- 
datepicker.css" rel="stylesheet">

<script 
src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.js"> 
</script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap- 
datepicker/1.5.0/js/bootstrap-         
datepicker.js"></script>
@endsection



via Chebli Mohamed

RDS Laravel SQLSTATE[HY000] [2002] Connection refused

I am trying to connect my Laravel 5.1 application using rds mysql. But it ended up in getting

SQLSTATE[HY000] [2002] Connection refused

The same rds database is using in other EC2 instance. But it works fine there. Only difference between two EC2 is the security group. As i come to notice that 3306 port should be open for mysql. I make it open in my security group. But still getting the same error. Can anybody help me to resolve this issue?

Thanks in advance for any help



via Chebli Mohamed

jeudi 10 mai 2018

White Screen of Death in Laravel Project

I have a Laravel 5.1 app that for some reason I can’t see any stack trace or an error at all.

I tried to name my function wrong to cause this error.

In a normal set up, I would see this

enter image description here

But another set up, I only see a white blank screen, even if I have APP_DEBUG set to true

I think I am haunted by the white screen of death. :(


Questions

I can only see this on 1 specific set up.

What should I check more on that set up to get this further ?


I'm open to any suggestions at this moment.

Any hints/suggestions / helps on this be will be much appreciated!

I've looked at all of these already

tail -f usr/share/ssc-portal/storage/logs/laravel.log
tail -f /var/log/nginx/error.log
tail -f /var/log/nginx/access.log
tail -f /var/log/fpm-php.www.log

/var/log/messages
/var/log/secure
/var/log/syslog



via Chebli Mohamed

mercredi 9 mai 2018

How to convert the below mentioned xml data into json array in laravel

Find below the xml data:

<?xml version="1.0" encoding="utf-8"?> <interface-response> <Command>CHECK</Command> <APIType>API.NET</APIType> <Language>eng</Language> <ErrCount>1</ErrCount> <errors> <Err1>User not permitted from this IP address - 113.193.131.41. See http://enom.help/whitelist for details</Err1> </errors> <ResponseCount>1</ResponseCount> <responses> <response> <ResponseNumber>713254</ResponseNumber> <ResponseString>Policy error; unauthorized; user(s)</ResponseString> </response> </responses> <MinPeriod>1</MinPeriod> <MaxPeriod>10</MaxPeriod> <Server>sjl0vwapi08</Server> <Site>eNom</Site> <IsLockable>True</IsLockable> <IsRealTimeTLD>True</IsRealTimeTLD> <TimeDifference>+7.00</TimeDifference> <ExecTime>0.034</ExecTime> <Done>true</Done> <TrackingKey>5baa515b-8e29-4517-b879-05ae68e94f9a</TrackingKey> <RequestDateTime>5/9/2018 3:49:10 AM</RequestDateTime> <debug/> </interface-response>

I need to convert the above xml data to json array and pass it to view from the controller.

Find below the conrtroller code:

public function test()
{

    $response = Curl::to('https://reseller.enom.com/interface.asp?command=check&sld=decksys&tld=info&responsetype=xml&uid=decksys&pw=Amy.th3ist4917')->get();         


 $data = simplexml_load_string($response);

 $configdata   = json_encode($data);

 $value = json_decode($configdata, true);

 return view('clientlayout.main.test', array('response' =>$response));

 }

Find below the view code:



The route is given below:

Route::get('/test','EnomController@test');

suggest a solution solve this and print the data in my view page.



via Chebli Mohamed

mardi 8 mai 2018

laravel implement languageCode_Country_Code in url

laravel implement languageCode_Country_Code in url along with page name translations.

en-us/contact es-ES/contacto de-DE/Kontakt



via Chebli Mohamed

lundi 7 mai 2018

upstream timed out (110: Connection timed out) while reading response header from upstream

I'm new to nginx server. The problem I'm facing currently is connection timed out issue after making a call from the iOS app. The Json I'm receiving is huge hence there is a timeout logged on the server.

Also checked with various answers posted here on stackoverflow regarding the same. But didn't help me out.

Below is my access log and error log. Please help.

Error log

upstream timed out (110: Connection timed out) while reading response header from upstream, client: xxxxxxxxxxx, server: xxxxxxxxxxx, request: "POST /api/event/gallery HTTP/1.1", upstream: "fastcgi://unix:/run/php/php7.0-fpm.sock", host: "xxxxxxxxxxx"

Access log

"POST /api/event/gallery HTTP/1.1" 504 192 "-" "mysite/2 CFNetwork/889.9 Darwin/16.7.0"

nginx.conf

user www-data;
worker_processes auto;
pid /run/nginx.pid;

events {
    worker_connections 768;
    # multi_accept on;
}

http {

    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    client_max_body_size 50M;

    ##
    # SSL Settings
    ##

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # Dropping SSLv3, ref: POODLE
    ssl_prefer_server_ciphers on;

    ##
    # Logging Settings
    ##

    access_log /var/log/nginx/access.log;
    error_log /var/log/nginx/error.log;

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    # gzip_vary on;
    # gzip_proxied any;
    # gzip_comp_level 6;
    # gzip_buffers 16 8k;
    # gzip_http_version 1.1;
    # gzip_types text/plain text/css application/json application/javascript text/xml application/xml application/xml+rss text/javascript;

    ##
    # Virtual Host Configs
    ##

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
}

#mail {
#   # See sample authentication script at:
#   # http://wiki.nginx.org/ImapAuthenticateWithApachePhpScript
# 
#   # auth_http localhost/auth.php;
#   # pop3_capabilities "TOP" "USER";
#   # imap_capabilities "IMAP4rev1" "UIDPLUS";
# 
#   server {
#       listen     localhost:110;
#       protocol   pop3;
#       proxy      on;
#   }
# 
#   server {
#       listen     localhost:143;
#       protocol   imap;
#       proxy      on;
#   }
#}



via Chebli Mohamed

jeudi 3 mai 2018

how to display the average rate of "tarifs" for a selected "tache"

i have 2 tables the first tache and table tarification tache .I would like to display in the interface tache.show the average rate of "tarifs" of this selected tache for all technicien. below is the code i used.........................................................................................................................................................................................................................................................................................................

@extends('Layouts/app')
@extends('Layouts.master')
@section('content')
@if(count($errors))
<div class="alert alert-danger" role="alert">
<ul>
@foreach($errors ->all() as $message)
<li></li>
@endforeach
</ul>
</div>
@endif
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>



<script type="text/javascript">

var getMetiersByTechnicienUrl = "";
var getTachesByMetierUrl = "";

 //console.log(getMetiersByTechnicienUrl,getTachesByMetierUrl, 
 getTarificationsByTacheUrl);
 function getMetiersByTechnicien(val) {
if(val.length>0) {
var technicien_id = val;
$.get(getMetiersByTechnicienUrl+'/'+technicien_id,function(res) {
    var html = '<option value="">-Select-</option>' ;
    $.each(res.metiers,function(index,item) {
        html+='<option 
 value="'+item.id+'">'+item.libelle_metier+'</option>';
    });
    $('#metiers').html(html);

});
}
}
function getTachesByMetier(val) {
 if(val.length>0) {
var metier_id = val;
$.get(getTachesByMetierUrl+'/'+metier_id,function(res) {
    var html = '<option value="">-Select-</option>' ;
    $.each(res.taches,function(index,item) {
        html+='<option 
value="'+item.id+'">'+item.libelle_tache+'</option>';
    });
    $('#taches').html(html);

});
}
}

</script>
<div class="container">
<div class="row"></div>
<div class="col-md-12">
Z
<div class="col-md-10">
<h1>Tarification tache</h1>
<form action=" " method="post">
 

<div class="form-group">
 <label for="technicien">Technicien</label>
    <select onchange="getMetiersByTechnicien(this.value)" 
name="technicien_id" 
id="technicien" class="form-control">
        <option value="">-Select-</option>
        @foreach($technicien as $t)
            <option value="">
                
            </option>
        @endforeach
    </select>
    </div>
    <div class="form-group">
    <div class="col-md-12">
        <div class="col-md-4">
    <label>Metier: </label>
    <select onchange="getTachesByMetier(this.value)" style="width: 
200px"    
    class="productm form-control" id="metiers">
     <option value="">-Select-</option>


    </select>
        </div>
        <div class="col-md-4">
            <label>tache: </label>
            <select style="width: 200px" class="productname form- 
control" 
name="tache_id" id="taches">
                <option value="">-Select-</option>
            </select>
        </div>
        <div class="col-md-4">
            <label>tarification: </label>
            <input style="width: 200px" class="productname form- 
control" type="text"  
name ="Tarif" class="form-control" value="">


        </div>


    </div>
    </div>
    <div class="form-group">
    <input type="submit" value = "enregistrer" class="form-control btn btn-primary">
     </div>
    </div>
    </div>
 </div>

@endsection

tarificationcontroller:

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\tarificationtache;
use App\technicien;
use App\tache;
use App\metier;

class TarificationController extends Controller
{
  /**
   * Display a listing of the resource.
   *
   * @return \Illuminate\Http\Response
   */
public function index()
{
$Listtache=tache::orderBy('libelle_tache')->get();
$Listtarification=tarificationtache::all();
return view('tarification.index',['tarification'=>$Listtarification]);
}

  /**
   * Show the form for creating a new resource.
   *
   * @return \Illuminate\Http\Response
   */
   public function create()

$technicien = technicien::orderBy('id','desc')->get();
$taches = Tache::orderBy('libelle_tache', 'asc')->get();
$metiers = Metier::orderBy('libelle_metier', 'asc')->get();
return view('tarification.create')->with('taches', $taches)- 
>with('technicien', $technicien)- 
>with('metiers', $metiers);
}

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

$tarification = new tarificationtache();
$tarification ->tache_id = $request->input('tache_id');
$tarification ->Tarif =$request->input('Tarif');
$tarification->save();
$tarification->techniciens()->attach($request->technicien_id);
return redirect('technicien');  }

  /**
   * Display the specified resource.
   *
   * @param  int  $id
   * @return \Illuminate\Http\Response
   */
   public function show($id)
   {
   //
   }

    /**
     * Show the form for editing the specified resource.
     *
     * @param  int  $id
     * @return \Illuminate\Http\Response
     */
    public function edit($id)
    {
    $tache=Tache::find($id);
    return view('tache.edit',['libelle_tache'=>$tache], 
    ['Tarif'=>$tache], 
    ['metier_id'=>$tache]);
    }

   /**
    * Update the specified resource in storage.
    *
    * @param  \Illuminate\Http\Request  $request
    * @param  int  $id
    * @return \Illuminate\Http\Response
    */
    public function update(Request $request, $id)
    {
    //
    }

   /**
    * Remove the specified resource from storage.
    *
    * @param  int  $id
    * @return \Illuminate\Http\Response
    */
    public function destroy($id)
    {
    $tache =Tache::find($id);
    $tache->delete();

    return redirect('tache');
    }
    public function getTarificationsByTache($tache_id)
    {
    $t =tache::find($tache_id);
    return response()->json(['tarifications' => $t- 
    >tarificationtache]);
    }

tache.show

@extends('Layouts/app')
@extends('Layouts.master')
@section('content')
<div class="container">
<div class="row">
    <div class="col-md-10">





<h1 align="center">Detail Tache</h1>

<div class="form-group">
        <label for="libelle_Tache">Libelle Tache</label>
        <label id="libelle_Tache" type="text" class="form-control"                      name="tache[libelle_Tache]" ></label>
    </div>
    <div class="form-group">
        <label for="Tarif">Tarif moyenne </label>
        <label id="Tarif" type="text" class="form-control" name="tache[Tarif]" ></label>
    </div>
    <div class="form-group">
        <label for="libelle_metier">Libelle Metier</label>
        <label id="prenom" type="text" class="form-control" name="metier[libelle_metier]" >         {$tache->metier->libelle_metier}}</label>
    </div>




        <div class="form-group" align="right">

                    <form action="" method="post">
                        
                        

                        <a href="" class="btn btn-default" class="btn btn-         primary">Retour</a>
                        <a href="" class="btn btn-default">Editer</a>
                        <button type="submit" class="btn btn-danger">Supprimer</button>
                    </form>
        </div>
</div>
@endsection

tache controler

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Tache;
use App\Metier;
use App\Technicien;
class TacheController extends Controller
{

protected function validator(array $data)
{
return Validator::make($data, [
    'Tarif' => 'required|floatval(6.3)',

]);
}
   /**
    * Display a listing of the resource.
    *
    * @return \Illuminate\Http\Response
    */
public function index(Request $request)
{


$tache=tache::with(['metier'])->get();

$search = $request->get('search');

$field = $request->get('field') != '' ? $request->get('field') : 
'libelle_tache';
$sort = $request->get('sort') != '' ? $request->get('sort') : 'asc';
$tache = new tache();
if ($request)

$tache = $tache->where('libelle_tache', 'like', '%' . $search . '%')
    ->orderBy($field, $sort)
    ->paginate(5)
    ->withPath('?search=' . $search . '&libelle_tache=' . $tache . 
'&field=' . $field . '&sort=' .          $sort);
    return view('tache.index',['tache'=>$tache]);

}

/**
 * Show the form for creating a new resource.
 *
 * @return \Illuminate\Http\Response
*/
public function create()
{

//$metiers = Costcenter::lists('libelle_metier', 'id');
$metiers = Metier::orderBy('libelle_metier', 'asc')->get();
return view('tache.create')->with('metiers', $metiers);
}

/**
* Store a newly created resource in storage.
*
* @param  \Illuminate\Http\Request  $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$tache = new Tache();
$tache ->libelle_tache =$request->input('libelle_tache');
$tache ->Tarif =$request->input('Tarif');
$tache ->metier_id = $request->input('metier_id');
$tache->save();
return redirect('tache');
}

/**
* Display the specified resource.
*
* @param  int  $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{

$tache = tache::findOrFail($id);
$metier = $tache->metier;
return view('tache.show' , compact('tache'))->with('metier',$metier);

}

/**
* Show the form for editing the specified resource.
*
* @param  int  $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$tache=Tache::find($id);
$metiers = Metier::orderBy('libelle_metier', 'asc')->get();
return view('tache.edit',['libelle_tache'=>$tache],['Tarif'=>$tache], 
['metier_id'=>$tache])-    >with('metiers', $metiers);
}

public function update(Request $request, $id)
{
// do some request validation
$tache=Tache::find($id);
$tache->update($request->all());
return redirect('tache');
}

/**
* Remove the specified resource from storage.
*
* @param  int  $id
* @return \Illuminate\Http\Response
*/
public function destroy($id)
{
$tache =Tache::find($id);
$tache->delete();

return redirect('tache');
}
public function getTachesByMetier($metier_id)
{
$t = Metier::find($metier_id);
return response()->json(['taches' => $t->taches]);
}

}



via Chebli Mohamed

How to autofill form with id from the previous Form

I'm trying to autofill form with id of techinician from the previous form after clicking add button. I have a list of technicians and each technician has multiple "tarification tache"associated with him then when i press the add button i am directed to the form to add "tarification tache" in this form i have to choose the technician. So I want the form to be autofilled with the ID of the technician in question and this from the previous form.

@extends('Layouts/app')
@extends('Layouts.master')
@section('content')
@if(count($errors))
<div class="alert alert-danger" role="alert">
<ul>
@foreach($errors ->all() as $message)
<li></li>
@endforeach
</ul>
</div>
@endif
<script 
src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>



<script type="text/javascript">

var getMetiersByTechnicienUrl = "";
var getTachesByMetierUrl = "";

//console.log(getMetiersByTechnicienUrl,getTachesByMetierUrl,
getTarificationsByTacheUrl);
function getMetiersByTechnicien(val) {
if(val.length>0) {
    var technicien_id = val;
    $.get(getMetiersByTechnicienUrl+'/'+technicien_id,function(res) {
        var html = '<option value="">-Select-</option>' ;
        $.each(res.metiers,function(index,item) {
            html+='<option 
value="'+item.id+'">'+item.libelle_metier+'</option>';
        });
        $('#metiers').html(html);

    });
 }
 }
    function getTachesByMetier(val) {
     if(val.length>0) {
    var metier_id = val;
    $.get(getTachesByMetierUrl+'/'+metier_id,function(res) {
        var html = '<option value="">-Select-</option>' ;
        $.each(res.taches,function(index,item) {
            html+='<option 
value="'+item.id+'">'+item.libelle_tache+'</option>';
        });
        $('#taches').html(html);

    });
    }
    }

    </script>
<div class="container">
    <div class="row"></div>
    <div class="col-md-12">
    Z
    <div class="col-md-10">
    <h1>Tarification tache</h1>
    <form action=" " method="post">
     

    <div class="form-group">
     <label for="technicien">Technicien</label>
        <select onchange="getMetiersByTechnicien(this.value)" 
name="technicien_id" 
    id="technicien" class="form-control">
            <option value="">-Select-</option>
            @foreach($technicien as $t)
                <option value="">
                    
                </option>
            @endforeach
        </select>
    </div>
    <div class="form-group">
    <div class="col-md-12">
            <div class="col-md-4">
    <label>Metier: </label>
    <select onchange="getTachesByMetier(this.value)" style="width: 
200px"    
    class="productm form-control" id="metiers">
         <option value="">-Select-</option>


    </select>
            </div>
            <div class="col-md-4">
                <label>tache: </label>
                <select style="width: 200px" class="productname form- 
control" 
name="tache_id" id="taches">
                    <option value="">-Select-</option>
                </select>
            </div>
            <div class="col-md-4">
                <label>tarification: </label>
                <input style="width: 200px" class="productname form- 
 control" type="text"  
 name ="Tarif" class="form-control" value="">


            </div>


        </div>
        </div>
        <div class="form-group">
        <input type="submit" value = "enregistrer" class="form-control 
 btn btn-primary">
    </div>
    </div>
        </div>
    </div>

@endsection

tarificationcontroller:

<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\tarificationtache;
use App\technicien;
use App\tache;
use App\metier;

class TarificationController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$Listtache=tache::orderBy('libelle_tache')->get();
$Listtarification=tarificationtache::all();
return view('tarification.index',['tarification'=>$Listtarification]);
}

/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
$technicien = technicien::orderBy('id','desc')->get();
$taches = Tache::orderBy('libelle_tache', 'asc')->get();
$metiers = Metier::orderBy('libelle_metier', 'asc')->get();
return view('tarification.create')->with('taches', $taches)- 
>with('technicien', $technicien)- 
>with('metiers', $metiers);
}

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

$tarification = new tarificationtache();
$tarification ->tache_id = $request->input('tache_id');
$tarification ->Tarif =$request->input('Tarif');
$tarification->save();
$tarification->techniciens()->attach($request->technicien_id);
return redirect('technicien');  }

/**
* Display the specified resource.
*
* @param  int  $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}

/**
* Show the form for editing the specified resource.
*
* @param  int  $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$tache=Tache::find($id);
return view('tache.edit',['libelle_tache'=>$tache],['Tarif'=>$tache], 
['metier_id'=>$tache]);
}

 /**
 * Update the specified resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
public function update(Request $request, $id)
{
//
}

 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
public function destroy($id)
{
$tache =Tache::find($id);
$tache->delete();

return redirect('tache');
}
public function getTarificationsByTache($tache_id)
{
$t =tache::find($tache_id);
return response()->json(['tarifications' => $t->tarificationtache]);
}



via Chebli Mohamed

jquery document.ready function is not working in iframe

I have an iframe. The iframe's src calls a specific controller's method to load a view in it. In the main view there are three buttons; Register, Login and Contact.

When I click on any of above buttons, a bootstrap modal is opened and using AJAX I render a HTML view page in the modal body section.

My problem is that when I click any of the buttons for the first time, my document.ready function works successfully but after closing that modal if I again click on same button my jQuery does not work at all.



via Chebli Mohamed

Which is best way about delete row and insert row in Laravel

As title, I have a table like student and another table is class. User can edit about student having some class. There is one to many relationship. When user edit student's class, I always must to delete this student's class. And insert the new class after that.

\App\class:where('student_id',$student->id)->delete();
foreach($request->input('class') as $class){
  $new = new \App\class;
  $new->student_id = $student->id;
  $new->class_id = $class;
  $new->save();
}

Is there have any solution about this issue? Thanks.



via Chebli Mohamed

mardi 1 mai 2018

Parse JSON Data from File upload

I have an input that select json file

in my controller, I did

dd(Input::all());

I got

enter image description here

My goal is to parse the JSON file that I got and loop through them.

I've tried

$string = file_get_contents(Input::get('fileinput'));
$json = json_decode($string, true);


Questions

How would one go about and debug this further ?


I'm open to any suggestions at this moment.

Any hints/suggestions / helps on this be will be much appreciated!



via Chebli Mohamed