mardi 27 février 2018

How to make a dropdown list suggest only options in relation with a selected value?

In my form below i have two dropdown lists the first one to choose "metier" and a second one to choose "tache" when i choose a "metier" i want that the second dropdown list "tache" suggest only options in relation with the already selected "Metier". Could anyone help me with this please.

enter image description here

create.blade.php

@extends('Layouts/app')
@extends('Layouts.master')
@section('content')
@if(count($errors))
<link rel="stylesheet" 
href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<script    src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">

 <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 class="col-md-10">
            <h1>Tarification tache</h1>
        <form action=" " method="post">
         

            <div class="form-group">
                <label for="technicien">Technicien</label>
                <select name="technicien_id" id="technicien" class="form-control" >

                        @foreach($techniciens as $techniciens)
                         <option value="">
                            
                         </option>
                        @endforeach
                </select>
            </div>
////////////
            
            <div class="form-group">
                <label for="metier">Libelle metier</label>
                <select name="metier" id="metier" class="form-control">

                        @foreach($metiers as $metier)
                         <option value="">
                            
                         </option>
                        @endforeach
                </select>
            </div>

            <div class="form-group">
                <label for="Tache">Libelle Tache</label>
                <select name="tache" id="Tache" class="form-control">

                        @foreach($taches as $tache)
                         <option value="">
                            
                         </option>
                        @endforeach
                </select>
            </div>
            

//////////////
            <div class="form-group">
                <label for="">Tarif</label>
                <input type="text"  name ="Tarif" class="form-control"value="">
            </div>
            <div class="form-group">
                <input type="submit" value = "enregistrer" class="form-control btn btn-primary">
            </div>
        </form>
    </div>
</div>


<script>
    $('#metier').on('change',function(e){
        console.long(e);
        var met_id = e.target.value;

        $.get('/ajax-tac?met_id=' + met_id, function(data){
            $('#tache').empty();
            $.each(data,function(index, tacObj){
                $('#tache').append('<option value="'+tacObj.id+'">'+catObj.libelle_tache+'</option>');
            });

        });

    });
</script>

@endsection

route.php

Route::get('/tarification', 'TarificationController@index');
Route::get('/tarification/create', 'TarificationController@create');
Route::post('/tarification', 'TarificationController@store');
Route::get('/tarification/{id}/edit', 'TarificationController@edit');
Route::put('/tarification/{id}', 'TarificationController@update');
Route::delete('/tarification/{id}', 'TarificationController@destroy');

Route::get('/ajax-metier',function(){
        $met_id = Input::get('met_id');
        $taches = tache::where('metier_id','=', $met_id)->get();
        return Response::json($metiers);
});

controller

public function create()
{
    $techniciens = technicien::orderBy('id','desc')->get();
    $taches = Tache::orderBy('libelle_tache', 'asc')->get();
    $metiers = Metier::all();
    return view('tarification.create')->with('taches', $taches)->with('techniciens', $techniciens)->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('home');
}



via Chebli Mohamed

Timeout value in case of queue:work

I have an app built on laravel 5.1 which is using RabbitMQ for job processing. The worker command is as follows:

php artisan queue:work --queue=[queue-name] --daemon --tries=5

What is the default timeout value in case of queue:work?

Also, if timeout is set via "set_time_limit" within a job and queue:work has its own timeout lets say 60 seconds, how the job processing is affected? What are the impacts on this conflicting timeouts?



via Chebli Mohamed

how to autofill a form field with only the "tâches" in relation with the chosen "Metier"?

I have this form and then I have in my database a set of "taches" that is linked to each "metier", I want to choose a "metier" in the field and the following field "taches" to propose me to choose only "taches" related to this "metier". Here is my code and my form.I would be very grateful if someone could help me with this.

create.blade.php

@extends('Layouts/app')
@extends('Layouts.master')
@section('content')
@if(count($errors))
<link rel="stylesheet" 

href="//netdna.bootstrapcdn.com/bootstrap/3.1.1/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>


<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 class="col-md-10">
            <h1>Tarification tache</h1>
        <form action=" " method="post">
         

            <div class="form-group">
                <label for="technicien">Technicien</label>
                <select name="technicien_id" id="technicien" class="form-control" >

                        @foreach($techniciens as $techniciens)
                         <option value="">
                            
                         </option>
                        @endforeach
                </select>
            </div>
 ////////////
            
            <div class="form-group">
                <label for="metier">Libelle metier</label>
                <select name="metier" id="metier" class="form-
 control">

                        @foreach($metiers as $metier)
                         <option value="">
                            
                         </option>
                        @endforeach
                </select>
            </div>

            <div class="form-group">
                <label for="Tache">Libelle Tache</label>
                <select name="tache" id="Tache" class="form-control">

                        @foreach($taches as $tache)
                         <option value="">
                            
                         </option>
                        @endforeach
                </select>
            </div>
            

       //////////////
            <div class="form-group">
                <label for="">Tarif</label>
                <input type="text"  name ="Tarif" class="form-control"value="">
            </div>
            <div class="form-group">
                <input type="submit" value = "enregistrer" class="form-control btn btn-primary">
            </div>
        </form>
    </div>
</div>


<script>
    $('#metier').on('change',function(e){
        console.long(e);
        var met_id = e.target.value;

        $.get('/ajax-tac?met_id=' + met_id, function(data){
            $('#tache').empty();
            $.each(data,function(index, tacObj){
                $('#tache').append('<option value="'+tacObj.id+'">'+catObj.libelle_tache+'</option>');
            });

        });

    });
</script>

@endsection

route.php

Route::get('/tarification', 'TarificationController@index');
Route::get('/tarification/create', 'TarificationController@create');
Route::post('/tarification', 'TarificationController@store');
Route::get('/tarification/{id}/edit', 'TarificationController@edit');
Route::put('/tarification/{id}', 'TarificationController@update');
Route::delete('/tarification/{id}', 'TarificationController@destroy');

Route::get('/ajax-metier',function(){
        $met_id = Input::get('met_id');
        $taches = tache::where('metier_id','=', $met_id)->get();
        return Response::json($metiers);
});

controller

public function create()
{
    $techniciens = technicien::orderBy('id','desc')->get();
    $taches = Tache::orderBy('libelle_tache', 'asc')->get();
    $metiers = Metier::all();
    return view('tarification.create')->with('taches', $taches)->with('techniciens', $techniciens)->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('home');
}



via Chebli Mohamed

Issue connecting custom queue driver laravel 5.1 'No connector for [mysql]'

I have searched the query all over internet but till have not come up to the solution for this issue. No connector for [mysql]

I have 2 Mysql Connections mysql and mysql2. mysql is to store data and mysql2 to store QUEUE JOBS.

Here below is the .ENV file details.

 DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_DATABASE=laravel_5_1
DB_USERNAME=root
DB_PASSWORD=

CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=mysql_queue

As you can see the about connection is DB_CONNECTION=mysql and my Queue driver QUEUE_DRIVER=mysql_queue

I have assigned and new queue driver named mysql_queue in queue.php

below is the queue.php code

 'default' => env('QUEUE_DRIVER', 'mysql_queue'),

'connections' => [
'mysql_queue' => [
            'connection' => 'mysql2',
            'driver' => 'mysql',
            'table' => 'jobs',
            'queue' => 'default',
            'expire' => 60,
        ],
]

'failed' => [
        'database' => env('DB_CONNECTION', 'mysql_queue'),
        'table' => 'failed_jobs',
    ],

As you can see the mysql_queue has 'connection' => 'mysql2', were i would like to store queued jobs. mysql2 is a new connection assiged in database.php below is the code.

'mysql2' => [
        'driver'    => 'mysql',
        'host'      => env('DB_HOST', 'localhost'),
        'database'  => env('DB_DATABASE', 'laravel_5_1_queue'),
        'username'  => env('DB_USERNAME', 'root'),
        'password'  => env('DB_PASSWORD', ''),
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
        'strict'    => false,
    ], 

Even after making these major changes as per laravel documentation i still get 'No connector for [mysql]' Error and unable to run QUEUED JOBS in background. kindly suggest me.

Thanks in Advance



via Chebli Mohamed

dimanche 25 février 2018

include a class from a different website in laravel new project

I am working on a backend api using laravel 5.6 Already have a website with tons of code - all the answers I found point at create a new folder and adding my classes there that is not an option. I would like to include the class from the main site (same server) and use the methods within laravel to generate the data from the api.

 Route::get('api/author/full/', array('uses' => 'AuthorController@getAuthor'));

I am using this line to include my class:

require_once('/var/www/html/modules/author/models/Author.class.php');

laravel is located in a subfolder at /var/www/html/api/

this is the error I get when i try to require that file from within the AuthorController :

 Fatal error: Call to undefined method ErrorException::getStatusCode() in  /html/api/app/Exceptions/Handler.php on line 61

Fatal error: Call to undefined method Symfony\Component\Debug\Exception\FatalErrorException::getStatusCode() in  /html/api/app/Exceptions/Handler.php on line 61

really tried everything here,included it in public/index.php and in other places and none of these things worked.



via Chebli Mohamed

new “Metier” is created when editing a “Metier ”

when I try to edit a "Metier", a new "Metier" is created and the old one stays the same. I want to crush the old "Metier" and create a new one just by editing. Could anyone help me with this please ?

Controller

 public function edit($id)
{
$metier=Metier::find($id);
return view('metier.edit',['libelle_metier'=>$metier]);
}

/**
 * Update the specified resource in storage.
 *
 * @param  \Illuminate\Http\Request  $request
 * @param  int  $id
 * @return \Illuminate\Http\Response
 */
 public function update(Request $request, $id)
{
$metier=Metier::find($id);
return view('metier.edit',['libelle_metier'=>$metier]);
}

View

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

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

route

Route::get('/metier', 'MetierController@index');
Route::get('/metier/create', 'MetierController@create');
Route::post('/metier', 'MetierController@store');
Route::get('/metier/{id}/show', 'MetierController@edit');
Route::get('/metier/{id}/edit', 'MetierController@edit');
Route::upd('/metier/{id}/update', 'MetierController@update');
Route::delete('/metier/{id}', 'MetierController@destroy')



via Chebli Mohamed

mercredi 21 février 2018

Laravel 5.1 Mail::queue Amazon SQS error 404

I first encountered with queue services (in that case it Amazon SQS). I configure queue.php and tried to send mail like that:

\Mail::queue('emails.reminder', [], function($message){
    $message->to('xxxxxxx@gmail.com', 'XXX')->subject('XXX');
});

But I have an error:

Error executing "SendMessage" on "https://sqs.eu-central-1.amazonaws.com/EmailQueue"; AWS HTTP error: Client error: `POST https://sqs.eu-central-1.amazonaws.com/EmailQueue` resulted in a `404 Not Found` response:
<?xml version="1.0"?><ErrorResponse xmlns="http://queue.amazonaws.com/doc/2012-11-05/"><Error><Type>Sender</Type><Code>I (truncated...)
InvalidAddress (client): The address /EmailQueue is not valid for this endpoint. - <?xml version="1.0"?><ErrorResponse xmlns="http://queue.amazonaws.com/doc/2012-11-05/"><Error><Type>Sender</Type><Code>InvalidAddress</Code><Message>The address /EmailQueue is not valid for this endpoint.</Message><Detail/></Error><RequestId>72ea954e-eaf4-55b8-96bb-c6499a1e4015</RequestId></ErrorResponse>

Can anyone help me?

Thanks!



via Chebli Mohamed